aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-02-22 11:25:13 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-02-22 11:25:13 +0000
commitdf7d84cf252a9443f748d8cef3821c7230ab54b4 (patch)
tree5dee4d3775a25beb64cafecb3d9bd85702cb467e
parent7fc504c6f7ecd1c64387470c38af6f903c013218 (diff)
downloadbusybox-w32-df7d84cf252a9443f748d8cef3821c7230ab54b4.tar.gz
busybox-w32-df7d84cf252a9443f748d8cef3821c7230ab54b4.tar.bz2
busybox-w32-df7d84cf252a9443f748d8cef3821c7230ab54b4.zip
Patch from Vodz, cleanup memory usage, send strdup error messages to
syslog.
-rw-r--r--networking/inetd.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/networking/inetd.c b/networking/inetd.c
index c930a892c..283c33bed 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -279,6 +279,16 @@ syslog_err_and_discard_dg(int se_socktype, const char *msg, ...)
279 _exit(1); 279 _exit(1);
280} 280}
281 281
282static char * inetd_strdup(const char *s)
283{
284 char *ms = strdup(s);
285
286 if(ms == NULL)
287 syslog_err_and_discard_dg(SOCK_STREAM, "strdup: %m");
288 return ms;
289}
290
291
282static servtab_t *getconfigent(void) 292static servtab_t *getconfigent(void)
283{ 293{
284 static servtab_t serv; 294 static servtab_t serv;
@@ -298,13 +308,15 @@ more:
298 if ((cp == NULL) || (*cp == '#')) { 308 if ((cp == NULL) || (*cp == '#')) {
299 goto more; 309 goto more;
300 } 310 }
311 /* make bind 0.0.0.0 and other zero default */
312 memset((char *)sep, 0, sizeof *sep);
301 313
302 cp_ptr = strtok_r(cp, " \t", &cp_ptr_ptr); 314 cp_ptr = strtok_r(cp, " \t", &cp_ptr_ptr);
303 if (cp_ptr == NULL) { 315 if (cp_ptr == NULL) {
304 /* Error */ 316 /* Error */
305 goto more; 317 goto more;
306 } 318 }
307 sep->se_service = bb_xstrdup(cp_ptr); 319 sep->se_service = inetd_strdup(cp_ptr);
308 320
309 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr); 321 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
310 if (cp_ptr == NULL) { 322 if (cp_ptr == NULL) {
@@ -339,7 +351,7 @@ more:
339 } 351 }
340 sep->se_family = AF_INET; 352 sep->se_family = AF_INET;
341 } 353 }
342 sep->se_proto = bb_xstrdup(cp_ptr); 354 sep->se_proto = inetd_strdup(cp_ptr);
343 355
344 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr); 356 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
345 if (cp_ptr == NULL) { 357 if (cp_ptr == NULL) {
@@ -361,14 +373,16 @@ more:
361 /* error */ 373 /* error */
362 goto more; 374 goto more;
363 } 375 }
376
377 sep->se_user = inetd_strdup(cp_ptr);
364 { 378 {
365 char *cp_ptr2 = strchr(cp_ptr, '.'); 379 char *cp_ptr2 = strchr(sep->se_user, '.');
380
366 if (cp_ptr2) { 381 if (cp_ptr2) {
367 *cp_ptr2++ = '\0'; 382 *cp_ptr2++ = '\0';
368 sep->se_group = bb_xstrdup(cp_ptr2);
369 } 383 }
384 sep->se_group = cp_ptr2;
370 } 385 }
371 sep->se_user = bb_xstrdup(cp_ptr);
372 386
373 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr); 387 cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr);
374 if (cp_ptr == NULL) { 388 if (cp_ptr == NULL) {
@@ -401,19 +415,16 @@ more:
401 sep->se_bi = NULL; 415 sep->se_bi = NULL;
402 } 416 }
403#endif 417#endif
404 sep->se_server = bb_xstrdup(cp_ptr); 418 sep->se_server = inetd_strdup(cp_ptr);
405 419
406 argc = 0; 420 argc = 0;
407 while ((cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr)) != NULL) { 421 while ((cp_ptr = strtok_r(NULL, " \t", &cp_ptr_ptr)) != NULL) {
408 if (argc < MAXARGV) { 422 if (argc < MAXARGV) {
409 sep->se_argv[argc++] = cp_ptr; 423 sep->se_argv[argc++] = inetd_strdup(cp_ptr);
410 } 424 }
411 } 425 }
412 while (argc <= MAXARGV) { 426 free(cp);
413 sep->se_argv[argc++] = NULL;
414 }
415 427
416 //free(cp); // BUG: cp is the argv[] container; we must not free it here!
417 return (sep); 428 return (sep);
418} 429}
419 430