Bug 45494 - rpm segfaults when expanding macros with parameters
rpm segfaults when expanding macros with parameters
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: rpm (Show other bugs)
4.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-06-22 03:19 EDT by Hans-Dieter Schuster
Modified: 2007-04-18 12:33 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-06-26 01:40:17 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Hans-Dieter Schuster 2001-06-22 03:19:23 EDT
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 03:24:01 EDT
Created attachment 21526 [details]
Patch for rpmio/macro.c (against rpm-4.0.2)
Comment 2 Hans-Dieter Schuster 2001-06-26 01:40:13 EDT
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 13:57:36 EDT
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.