Bug 45494 - rpm segfaults when expanding macros with parameters
Summary: rpm segfaults when expanding macros with parameters
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: rpm
Version: 4.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-06-22 07:19 UTC by Hans-Dieter Schuster
Modified: 2007-04-18 16:33 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-06-26 05:40:17 UTC
Embargoed:


Attachments (Terms of Use)
Patch for rpmio/macro.c (against rpm-4.0.2) (1.37 KB, patch)
2001-06-22 07:24 UTC, Hans-Dieter Schuster
no flags Details | Diff

Description Hans-Dieter Schuster 2001-06-22 07:19:23 UTC
Description of Problem:
rpm segfaults when a macro with parameters is used.
Please find attached a patch that fixes the problem.

How Reproducible:
see below

Steps to Reproduce:

1. Put the following macro in your ~/.rpmmacros
	%my_macro(ab) %0 %** [%*] -a: (%{-a}) -b: (%{-b})
2. Run: rpm --eval '%my_macro -a -b arg1 arg2'


Actual Results:
Segmentation fault (core dumped)

Expected Results:
Text output: "my_macro -a -b arg1 arg2 [arg1 arg2] -a: (-a) -b: (-b)"

Additional Information:
	
I fixed this with the following patch:

--- rpmio/macro.c.orig	Fri Jan 19 02:47:25 2001
+++ rpmio/macro.c	Thu Jun 21 17:39:30 2001
@@ -759,7 +759,7 @@
     b = be = stpcpy(buf, me->name);
 
     addMacro(mb->mc, "0", NULL, buf, mb->depth);
-    
+
     argc = 1;	/* XXX count argv[0] */
 
     /* Copy args into buf until lastc */
@@ -801,7 +801,7 @@
     /* Build argv array */
     argv = (const char **) alloca((argc + 1) * sizeof(char *));
     be[-1] = ' ';	/*  be - 1 == b + strlen(b) == buf + strlen(buf)  */
-    buf[0] = '\0';
+    be[0] = '\0';
     b = buf;
     for (c = 0; c < argc; c++) {
 	argv[c] = b;
@@ -818,6 +818,11 @@
 	if (c == '?' || (o = strchr(opts, c)) == NULL) {
 	    rpmError(RPMERR_BADSPEC, _("Unknown option %c in %s(%s)\n"),
 			c, me->name, opts);
+	    /* Reset getopt() state */
+	    optind = 0;
+	    optarg = NULL;
+	    argv[1] = NULL;
+	    getopt(1,(char **)argv,"xyz");
 	    return se;
 	}
 	*be++ = '-';
@@ -845,12 +850,19 @@
     for (c = optind; c < argc; c++) {
 	sprintf(aname, "%d", (c - optind + 1));
 	addMacro(mb->mc, aname, NULL, argv[c], mb->depth);
-	*be++ = ' ';
 	be = stpcpy(be, argv[c]);
+	*be++ = ' ';
     }
-
+    if (be > b)
+	be[-1] = '\0';
     /* Add unexpanded args as macro. */
     addMacro(mb->mc, "*", NULL, b, mb->depth);
+
+    /* Reset getopt() state */
+    optind = 0;
+    optarg = NULL;
+    argv[1] = NULL;
+    getopt(1,(char **)argv,"xyz");
 
     return se;
 }

Comment 1 Hans-Dieter Schuster 2001-06-22 07:24:01 UTC
Created attachment 21526 [details]
Patch for rpmio/macro.c (against rpm-4.0.2)

Comment 2 Hans-Dieter Schuster 2001-06-26 05:40:13 UTC
Please close this bug, it was opened against the wrong version of Red Hat Linux
(correct version is 7.1)

Comment 3 Jeff Johnson 2001-06-26 17:57:36 UTC
OK, closed. FWIW, there was a simpler patch recently added to rpm-4.0.3
that sets optind =1 on glibc systems. That appears to be the same problem
that you were experiencing. Please reopen this bug if your problem persists.


Note You need to log in before you can comment on or make changes to this bug.