summaryrefslogtreecommitdiff
path: root/system/pdksh/patches/113_OpenBSD-memory.patch
blob: 79e7b59833ad14bc5426f0aceb47a5deb58d1438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
From OpenBSD:

2009-04-19 22:34  sthen

        * misc.c (1.37): don't print extraneous padding characters when
          tab-completion file/command lists encounter a name too long for
          the width of the terminal.

          from Matthew Haub, no objections krw@.

2008-08-11 23:50  jaredy

        * tree.c (1.19): plug a memleak when freeing io redirection in
          commands.  the leaked memory is actually reclaimed when the
          command finishes but may grow until that happens, e.g. during
          command execution.

          ok phessler@.  testing sobrado@ jmc@ oga@.

2008-07-23 18:34  jaredy

        * c_sh.c (1.38), syn.c (1.28): fix stack abuse in the `time'
          commmand, using alloc()'d memory instead.

          reported by Thorsten Glaser, thanks.

          ok millert@, earlier version miod@

2008-07-21 19:30  millert

        * alloc.c (1.8): Extra sanity checking for afree();  OK deraadt@
          and pvalchev@

2008-07-12 14:33  miod

        * misc.c (1.34): Fix a strlcpy() bound.



Index: pdksh-5.2.14/tree.c
===================================================================
--- pdksh-5.2.14.orig/tree.c	2009-09-19 11:22:37.000000000 +0200
+++ pdksh-5.2.14/tree.c	2009-09-19 12:06:43.000000000 +0200
@@ -755,4 +755,5 @@
 			afree((void*)p->heredoc, ap);
 		afree((void*)p, ap);
 	}
+	afree(iow, ap);
 }
Index: pdksh-5.2.14/syn.c
===================================================================
--- pdksh-5.2.14.orig/syn.c	2009-09-19 11:22:37.000000000 +0200
+++ pdksh-5.2.14/syn.c	2009-09-19 12:06:43.000000000 +0200
@@ -375,6 +375,11 @@
 	  case TIME:
 		syniocf &= ~(KEYWORD|ALIAS);
 		t = pipeline(0);
+		if (t) {
+			t->str = alloc(2, ATEMP);
+			t->str[0] = '\0'; /* TF_* flags */
+			t->str[1] = '\0';
+		}
 		t = block(TTIME, t, NOBLOCK, NOWORDS);
 		break;
 
Index: pdksh-5.2.14/alloc.c
===================================================================
--- pdksh-5.2.14.orig/alloc.c	2009-09-19 11:22:37.000000000 +0200
+++ pdksh-5.2.14/alloc.c	2009-09-19 12:06:43.000000000 +0200
@@ -894,13 +894,20 @@
 void
 afree(void *ptr, Area *ap)
 {
-	struct link *l;
+	struct link *l, *l2;
 
 	if (!ptr)
 		return;
 
 	l = P2L(ptr);
 
+	for (l2 = ap->freelist; l2 != NULL; l2 = l2->next) {
+		if (l == l2)
+			break;
+	}
+	if (l2 == NULL)
+		internal_errorf(1, "afree: %p not present in area %p", ptr, ap);
+
 	if (l->prev)
 		l->prev->next = l->next;
 	else
Index: pdksh-5.2.14/c_sh.c
===================================================================
--- pdksh-5.2.14.orig/c_sh.c	2009-09-19 11:55:01.000000000 +0200
+++ pdksh-5.2.14/c_sh.c	2009-09-19 12:06:43.000000000 +0200
@@ -738,7 +738,6 @@
 	clock_t t0t, t1t = 0;
 	int tf = 0;
 	extern clock_t j_usrtime, j_systime; /* computed by j_wait */
-	char opts[1];
 
 	t0t = ksh_times(&t0);
 	if (t->left) {
@@ -751,11 +750,9 @@
 		 * really work as it only counts the last job).
 		 */
 		j_usrtime = j_systime = 0;
-		if (t->left->type == TCOM)
-			t->left->str = opts;
-		opts[0] = 0;
 		rv = execute(t->left, f | XTIME, xerrok);
-		tf |= opts[0];
+		if (t->left->type == TCOM)
+			tf |= t->left->str[0];
 		t1t = ksh_times(&t1);
 	} else
 		tf = TF_NOARGS;
Index: pdksh-5.2.14/misc.c
===================================================================
--- pdksh-5.2.14.orig/misc.c	2009-09-19 11:22:37.000000000 +0200
+++ pdksh-5.2.14/misc.c	2009-09-19 12:06:43.000000000 +0200
@@ -1123,6 +1123,7 @@
 	int r, c;
 	int rows, cols;
 	int nspace;
+	int col_width;
 
 	/* max_width + 1 for the space.  Note that no space
 	 * is printed after the last column to avoid problems
@@ -1141,6 +1142,9 @@
 			rows = n;
 	}
 
+	col_width = max_width;
+	if (cols == 1)
+		col_width = 0; /* Don't pad entries in single column output. */
 	nspace = (x_cols - max_width * cols) / cols;
 	if (nspace <= 0)
 		nspace = 1;
@@ -1149,7 +1153,7 @@
 			i = c * rows + r;
 			if (i < n) {
 				shf_fprintf(shf, "%-*s",
-					max_width,
+					col_width,
 					(*func)(arg, i, str, max_width + 1));
 				if (c + 1 < cols)
 					shf_fprintf(shf, "%*s", nspace, null);