aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-28 02:24:59 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-28 02:24:59 +0000
commitc4523c2b3da206312ed0b007a46eace58659ec31 (patch)
tree5d4f169b7de1d73e7948f2bf8ecad79df2f18c6b
parent2570b2e5759e8ac32b0922d71056bd426caae9f1 (diff)
downloadbusybox-w32-c4523c2b3da206312ed0b007a46eace58659ec31.tar.gz
busybox-w32-c4523c2b3da206312ed0b007a46eace58659ec31.tar.bz2
busybox-w32-c4523c2b3da206312ed0b007a46eace58659ec31.zip
fix a few stray unguarded strdup's
-rw-r--r--e2fsprogs/old_e2fsprogs/fsck.c2
-rw-r--r--editors/ed.c259
-rw-r--r--networking/httpd.c16
-rw-r--r--selinux/sestatus.c4
4 files changed, 137 insertions, 144 deletions
diff --git a/e2fsprogs/old_e2fsprogs/fsck.c b/e2fsprogs/old_e2fsprogs/fsck.c
index a51c33a1c..9cb9f754d 100644
--- a/e2fsprogs/old_e2fsprogs/fsck.c
+++ b/e2fsprogs/old_e2fsprogs/fsck.c
@@ -285,7 +285,7 @@ static char *string_copy(const char *s)
285 285
286 if (!s) 286 if (!s)
287 return 0; 287 return 0;
288 ret = strdup(s); 288 ret = xstrdup(s);
289 return ret; 289 return ret;
290} 290}
291 291
diff --git a/editors/ed.c b/editors/ed.c
index 9606cfdde..2f3bf03bf 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -119,7 +119,7 @@ int ed_main(int argc ATTRIBUTE_UNUSED, char **argv)
119static void doCommands(void) 119static void doCommands(void)
120{ 120{
121 const char *cp; 121 const char *cp;
122 char *endbuf, *newname, buf[USERSIZE]; 122 char *endbuf, buf[USERSIZE];
123 int len, num1, num2; 123 int len, num1, num2;
124 smallint have1, have2; 124 smallint have1, have2;
125 125
@@ -168,162 +168,157 @@ static void doCommands(void)
168 num2 = num1; 168 num2 = num1;
169 169
170 switch (*cp++) { 170 switch (*cp++) {
171 case 'a': 171 case 'a':
172 addLines(num1 + 1); 172 addLines(num1 + 1);
173 break; 173 break;
174 174
175 case 'c': 175 case 'c':
176 deleteLines(num1, num2); 176 deleteLines(num1, num2);
177 addLines(num1); 177 addLines(num1);
178 break; 178 break;
179 179
180 case 'd': 180 case 'd':
181 deleteLines(num1, num2); 181 deleteLines(num1, num2);
182 break; 182 break;
183 183
184 case 'f': 184 case 'f':
185 if (*cp && !isblank(*cp)) { 185 if (*cp && !isblank(*cp)) {
186 bb_error_msg("bad file command"); 186 bb_error_msg("bad file command");
187 break;
188 }
189 cp = skip_blank(cp);
190 if (*cp == '\0') {
191 if (fileName)
192 printf("\"%s\"\n", fileName);
193 else
194 printf("No file name\n");
195 break;
196 }
197 newname = strdup(cp);
198 if (newname == NULL) {
199 bb_error_msg("no memory for file name");
200 break;
201 }
202 free(fileName);
203 fileName = newname;
204 break; 187 break;
205 188 }
206 case 'i': 189 cp = skip_blank(cp);
207 addLines(num1); 190 if (*cp == '\0') {
191 if (fileName)
192 printf("\"%s\"\n", fileName);
193 else
194 printf("No file name\n");
208 break; 195 break;
196 }
197 free(fileName);
198 fileName = xstrdup(cp);
199 break;
209 200
210 case 'k': 201 case 'i':
211 cp = skip_blank(cp); 202 addLines(num1);
212 if ((*cp < 'a') || (*cp > 'z') || cp[1]) { 203 break;
213 bb_error_msg("bad mark name");
214 break;
215 }
216 marks[*cp - 'a'] = num2;
217 break;
218 204
219 case 'l': 205 case 'k':
220 printLines(num1, num2, TRUE); 206 cp = skip_blank(cp);
207 if ((*cp < 'a') || (*cp > 'z') || cp[1]) {
208 bb_error_msg("bad mark name");
221 break; 209 break;
210 }
211 marks[*cp - 'a'] = num2;
212 break;
222 213
223 case 'p': 214 case 'l':
224 printLines(num1, num2, FALSE); 215 printLines(num1, num2, TRUE);
225 break; 216 break;
226 217
227 case 'q': 218 case 'p':
228 cp = skip_blank(cp); 219 printLines(num1, num2, FALSE);
229 if (have1 || *cp) { 220 break;
230 bb_error_msg("bad quit command");
231 break;
232 }
233 if (!dirty)
234 return;
235 len = read_line_input("Really quit? ", buf, 16, NULL);
236 /* read error/EOF - no way to continue */
237 if (len < 0)
238 return;
239 cp = skip_blank(buf);
240 if ((*cp | 0x20) == 'y') /* Y or y */
241 return;
242 break;
243 221
244 case 'r': 222 case 'q':
245 if (*cp && !isblank(*cp)) { 223 cp = skip_blank(cp);
246 bb_error_msg("bad read command"); 224 if (have1 || *cp) {
247 break; 225 bb_error_msg("bad quit command");
248 }
249 cp = skip_blank(cp);
250 if (*cp == '\0') {
251 bb_error_msg("no file name");
252 break;
253 }
254 if (!have1)
255 num1 = lastNum;
256 if (readLines(cp, num1 + 1))
257 break;
258 if (fileName == NULL)
259 fileName = strdup(cp);
260 break; 226 break;
227 }
228 if (!dirty)
229 return;
230 len = read_line_input("Really quit? ", buf, 16, NULL);
231 /* read error/EOF - no way to continue */
232 if (len < 0)
233 return;
234 cp = skip_blank(buf);
235 if ((*cp | 0x20) == 'y') /* Y or y */
236 return;
237 break;
261 238
262 case 's': 239 case 'r':
263 subCommand(cp, num1, num2); 240 if (*cp && !isblank(*cp)) {
241 bb_error_msg("bad read command");
264 break; 242 break;
265 243 }
266 case 'w': 244 cp = skip_blank(cp);
267 if (*cp && !isblank(*cp)) { 245 if (*cp == '\0') {
268 bb_error_msg("bad write command"); 246 bb_error_msg("no file name");
269 break;
270 }
271 cp = skip_blank(cp);
272 if (!have1) {
273 num1 = 1;
274 num2 = lastNum;
275 }
276 if (*cp == '\0')
277 cp = fileName;
278 if (cp == NULL) {
279 bb_error_msg("no file name specified");
280 break;
281 }
282 writeLines(cp, num1, num2);
283 break; 247 break;
284 248 }
285 case 'z': 249 if (!have1)
286 switch (*cp) { 250 num1 = lastNum;
287 case '-': 251 if (readLines(cp, num1 + 1))
288 printLines(curNum - 21, curNum, FALSE);
289 break;
290 case '.':
291 printLines(curNum - 11, curNum + 10, FALSE);
292 break;
293 default:
294 printLines(curNum, curNum + 21, FALSE);
295 break;
296 }
297 break; 252 break;
253 if (fileName == NULL)
254 fileName = xstrdup(cp);
255 break;
298 256
299 case '.': 257 case 's':
300 if (have1) { 258 subCommand(cp, num1, num2);
301 bb_error_msg("no arguments allowed"); 259 break;
302 break; 260
303 } 261 case 'w':
304 printLines(curNum, curNum, FALSE); 262 if (*cp && !isblank(*cp)) {
263 bb_error_msg("bad write command");
264 break;
265 }
266 cp = skip_blank(cp);
267 if (!have1) {
268 num1 = 1;
269 num2 = lastNum;
270 }
271 if (*cp == '\0')
272 cp = fileName;
273 if (cp == NULL) {
274 bb_error_msg("no file name specified");
305 break; 275 break;
276 }
277 writeLines(cp, num1, num2);
278 break;
306 279
280 case 'z':
281 switch (*cp) {
307 case '-': 282 case '-':
308 if (setCurNum(curNum - 1)) 283 printLines(curNum - 21, curNum, FALSE);
309 printLines(curNum, curNum, FALSE);
310 break; 284 break;
311 285 case '.':
312 case '=': 286 printLines(curNum - 11, curNum + 10, FALSE);
313 printf("%d\n", num1);
314 break; 287 break;
315 case '\0': 288 default:
316 if (have1) { 289 printLines(curNum, curNum + 21, FALSE);
317 printLines(num2, num2, FALSE);
318 break;
319 }
320 if (setCurNum(curNum + 1))
321 printLines(curNum, curNum, FALSE);
322 break; 290 break;
291 }
292 break;
323 293
324 default: 294 case '.':
325 bb_error_msg("unimplemented command"); 295 if (have1) {
296 bb_error_msg("no arguments allowed");
297 break;
298 }
299 printLines(curNum, curNum, FALSE);
300 break;
301
302 case '-':
303 if (setCurNum(curNum - 1))
304 printLines(curNum, curNum, FALSE);
305 break;
306
307 case '=':
308 printf("%d\n", num1);
309 break;
310 case '\0':
311 if (have1) {
312 printLines(num2, num2, FALSE);
326 break; 313 break;
314 }
315 if (setCurNum(curNum + 1))
316 printLines(curNum, curNum, FALSE);
317 break;
318
319 default:
320 bb_error_msg("unimplemented command");
321 break;
327 } 322 }
328 } 323 }
329} 324}
diff --git a/networking/httpd.c b/networking/httpd.c
index 5e6037cbe..b4a8d277b 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -800,7 +800,7 @@ static char *encodeString(const char *string)
800/* 800/*
801 * Given a URL encoded string, convert it to plain ascii. 801 * Given a URL encoded string, convert it to plain ascii.
802 * Since decoding always makes strings smaller, the decode is done in-place. 802 * Since decoding always makes strings smaller, the decode is done in-place.
803 * Thus, callers should strdup() the argument if they do not want the 803 * Thus, callers should xstrdup() the argument if they do not want the
804 * argument modified. The return is the original pointer, allowing this 804 * argument modified. The return is the original pointer, allowing this
805 * function to be easily used as arguments to other functions. 805 * function to be easily used as arguments to other functions.
806 * 806 *
@@ -1725,9 +1725,7 @@ static int checkPerm(const char *path, const char *request)
1725 1725
1726 if (strcmp(p, request) == 0) { 1726 if (strcmp(p, request) == 0) {
1727 set_remoteuser_var: 1727 set_remoteuser_var:
1728 remoteuser = strdup(request); 1728 remoteuser = xstrndup(request, u - request);
1729 if (remoteuser)
1730 remoteuser[u - request] = '\0';
1731 return 1; /* Ok */ 1729 return 1; /* Ok */
1732 } 1730 }
1733 /* unauthorized */ 1731 /* unauthorized */
@@ -1990,13 +1988,13 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
1990#endif 1988#endif
1991#if ENABLE_FEATURE_HTTPD_CGI 1989#if ENABLE_FEATURE_HTTPD_CGI
1992 else if (STRNCASECMP(iobuf, "Cookie:") == 0) { 1990 else if (STRNCASECMP(iobuf, "Cookie:") == 0) {
1993 cookie = strdup(skip_whitespace(iobuf + sizeof("Cookie:")-1)); 1991 cookie = xstrdup(skip_whitespace(iobuf + sizeof("Cookie:")-1));
1994 } else if (STRNCASECMP(iobuf, "Content-Type:") == 0) { 1992 } else if (STRNCASECMP(iobuf, "Content-Type:") == 0) {
1995 content_type = strdup(skip_whitespace(iobuf + sizeof("Content-Type:")-1)); 1993 content_type = xstrdup(skip_whitespace(iobuf + sizeof("Content-Type:")-1));
1996 } else if (STRNCASECMP(iobuf, "Referer:") == 0) { 1994 } else if (STRNCASECMP(iobuf, "Referer:") == 0) {
1997 referer = strdup(skip_whitespace(iobuf + sizeof("Referer:")-1)); 1995 referer = xstrdup(skip_whitespace(iobuf + sizeof("Referer:")-1));
1998 } else if (STRNCASECMP(iobuf, "User-Agent:") == 0) { 1996 } else if (STRNCASECMP(iobuf, "User-Agent:") == 0) {
1999 user_agent = strdup(skip_whitespace(iobuf + sizeof("User-Agent:")-1)); 1997 user_agent = xstrdup(skip_whitespace(iobuf + sizeof("User-Agent:")-1));
2000 } 1998 }
2001#endif 1999#endif
2002#if ENABLE_FEATURE_HTTPD_BASIC_AUTH 2000#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
@@ -2377,7 +2375,7 @@ int httpd_main(int argc ATTRIBUTE_UNUSED, char **argv)
2377 * Besides, it is also smaller. */ 2375 * Besides, it is also smaller. */
2378 { 2376 {
2379 char *p = getenv("PATH"); 2377 char *p = getenv("PATH");
2380 /* env strings themself are not freed, no need to strdup(p): */ 2378 /* env strings themself are not freed, no need to xstrdup(p): */
2381 clearenv(); 2379 clearenv();
2382 if (p) 2380 if (p)
2383 putenv(p - 5); 2381 putenv(p - 5);
diff --git a/selinux/sestatus.c b/selinux/sestatus.c
index 43e31d455..ec39afc21 100644
--- a/selinux/sestatus.c
+++ b/selinux/sestatus.c
@@ -78,10 +78,10 @@ static void read_config(char **pc, int npc, char **fc, int nfc)
78 section = 2; 78 section = 2;
79 } else { 79 } else {
80 if (section == 1 && pc_ofs < npc -1) { 80 if (section == 1 && pc_ofs < npc -1) {
81 pc[pc_ofs++] = strdup(buf); 81 pc[pc_ofs++] = xstrdup(buf);
82 pc[pc_ofs] = NULL; 82 pc[pc_ofs] = NULL;
83 } else if (section == 2 && fc_ofs < nfc - 1) { 83 } else if (section == 2 && fc_ofs < nfc - 1) {
84 fc[fc_ofs++] = strdup(buf); 84 fc[fc_ofs++] = xstrdup(buf);
85 fc[fc_ofs] = NULL; 85 fc[fc_ofs] = NULL;
86 } 86 }
87 } 87 }