View | Details | Raw Unified | Return to bug 247529 | Differences between
and this patch

Collapse All | Expand All

(-)b/devel/popt/Makefile (+1 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME=	popt
4
PORTNAME=	popt
5
PORTVERSION=	1.18
5
PORTVERSION=	1.18
6
PORTREVISION=	1
6
CATEGORIES=	devel
7
CATEGORIES=	devel
7
MASTER_SITES=	http://ftp.rpm.org/popt/releases/popt-1.x/
8
MASTER_SITES=	http://ftp.rpm.org/popt/releases/popt-1.x/
8
9
(-)b/devel/popt/files/patch-src_popt.c (+55 lines)
Added Link Here
1
--- src/popt.c.orig	2020-05-18 07:43:13 UTC
2
+++ src/popt.c
3
@@ -168,6 +168,7 @@ poptContext poptGetContext(const char * name, int argc
4
 	con->os->next = 1;		/* skip argv[0] */
5
 
6
     con->leftovers = calloc( (size_t)(argc + 1), sizeof(*con->leftovers) );
7
+    con->allocLeftovers = argc + 1;
8
     con->options = options;
9
     con->aliases = NULL;
10
     con->numAliases = 0;
11
@@ -1269,8 +1270,21 @@ int poptGetNextOpt(poptContext con)
12
 		    con->os->nextArg = xstrdup(origOptString);
13
 		    return 0;
14
 		}
15
-		if (con->leftovers != NULL)	/* XXX can't happen */
16
-		    con->leftovers[con->numLeftovers++] = origOptString;
17
+		if (con->leftovers != NULL) {	/* XXX can't happen */
18
+		    /* One might think we can never overflow the leftovers
19
+		       array.  Actually, that's true, as long as you don't
20
+		       use poptStuffArgs()... */
21
+		    if ((con->numLeftovers + 1) >= (con->allocLeftovers)) {
22
+			con->allocLeftovers += 10;
23
+			con->leftovers =
24
+			    realloc(con->leftovers,
25
+				    sizeof(*con->leftovers) * con->allocLeftovers);
26
+		    }
27
+		    con->leftovers[con->numLeftovers++]
28
+			= xstrdup(origOptString); /* so a free of a stuffed
29
+						     argv doesn't give us a
30
+						     dangling pointer */
31
+		}
32
 		continue;
33
 	    }
34
 
35
@@ -1519,6 +1533,8 @@ poptItem poptFreeItems(poptItem items, int nitems)
36
 
37
 poptContext poptFreeContext(poptContext con)
38
 {
39
+    int i;
40
+
41
     if (con == NULL) return con;
42
     poptResetContext(con);
43
 
44
@@ -1528,7 +1544,11 @@ poptContext poptFreeContext(poptContext con)
45
     con->execs = poptFreeItems(con->execs, con->numExecs);
46
     con->numExecs = 0;
47
 
48
+    for (i = 0; i < con->numLeftovers; i++) {
49
+        con->leftovers[i] = _free(&con->leftovers[i]);
50
+    }
51
     con->leftovers = _free(con->leftovers);
52
+
53
     con->finalArgv = _free(con->finalArgv);
54
     con->appName = _free(con->appName);
55
     con->otherHelp = _free(con->otherHelp);
(-)b/devel/popt/files/patch-src_poptint.h (-1 / +10 lines)
Added Link Here
0
- 
1
--- src/poptint.h.orig	2020-05-18 07:43:13 UTC
2
+++ src/poptint.h
3
@@ -94,6 +94,7 @@ struct poptContext_s {
4
     struct optionStackEntry * os;
5
     poptArgv leftovers;
6
     int numLeftovers;
7
+    int allocLeftovers;
8
     int nextLeftover;
9
     const struct poptOption * options;
10
     int restLeftover;

Return to bug 247529