aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-12-26 20:44:45 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-12-26 20:44:45 +0000
commitabee3d0e0dc7c7e4b733b0145c56bf8159a37a69 (patch)
treebf000d88c4044106f689060ee795d49f9a9116f6 /networking
parentd55268d0d497856a34f732aca158d07276358ab6 (diff)
downloadbusybox-w32-abee3d0e0dc7c7e4b733b0145c56bf8159a37a69.tar.gz
busybox-w32-abee3d0e0dc7c7e4b733b0145c56bf8159a37a69.tar.bz2
busybox-w32-abee3d0e0dc7c7e4b733b0145c56bf8159a37a69.zip
Fix xmalloc_fgets_str so that it really does NOT strip terminator.
Add xmalloc_fgetline_str which does strip terminator, and use it in dpkg instead of xmalloc_fgets_str. netstat: use xmalloc_fgets_str - allows to eat strings with NULs (this fixes bug with some weird /proc/net/unix input) function old new delta xmalloc_fgets_internal - 191 +191 xmalloc_fgetline_str - 18 +18 do_info 116 120 +4 unix_do_one 451 447 -4 tcp_do_one 423 419 -4 send_tree 369 365 -4 xmalloc_fgets_str 178 15 -163 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 1/4 up/down: 213/-175) Total: 38 bytes text data bss dec hex filename 778445 832 7344 786621 c00bd busybox_old 778483 832 7344 786659 c00e3 busybox_unstripped
Diffstat (limited to 'networking')
-rw-r--r--networking/netstat.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/networking/netstat.c b/networking/netstat.c
index d86c2ff5e..1c78f9d19 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -170,6 +170,11 @@ static void tcp_do_one(int lnr, char *line)
170 rem_addr, &rem_port, &state, 170 rem_addr, &rem_port, &state,
171 &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); 171 &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
172 172
173 if (num < 10) {
174 bb_error_msg("warning, got bogus tcp line");
175 return;
176 }
177
173 if (strlen(local_addr) > 8) { 178 if (strlen(local_addr) > 8) {
174#if ENABLE_FEATURE_IPV6 179#if ENABLE_FEATURE_IPV6
175 build_ipv6_addr(local_addr, &localaddr); 180 build_ipv6_addr(local_addr, &localaddr);
@@ -180,11 +185,6 @@ static void tcp_do_one(int lnr, char *line)
180 build_ipv4_addr(rem_addr, &remaddr); 185 build_ipv4_addr(rem_addr, &remaddr);
181 } 186 }
182 187
183 if (num < 10) {
184 bb_error_msg("warning, got bogus tcp line");
185 return;
186 }
187
188 if ((rem_port && (flags & NETSTAT_CONNECTED)) 188 if ((rem_port && (flags & NETSTAT_CONNECTED))
189 || (!rem_port && (flags & NETSTAT_LISTENING)) 189 || (!rem_port && (flags & NETSTAT_LISTENING))
190 ) { 190 ) {
@@ -349,17 +349,16 @@ static void unix_do_one(int nr, char *line)
349 const char *ss_proto, *ss_state, *ss_type; 349 const char *ss_proto, *ss_state, *ss_type;
350 char ss_flags[32]; 350 char ss_flags[32];
351 351
352 /* TODO: currently we stop at first NUL byte. Is it a problem? */
353
352 if (nr == 0) 354 if (nr == 0)
353 return; /* skip header */ 355 return; /* skip header */
354 356
355 { 357 *strchrnul(line, '\n') = '\0';
356 char *last = last_char_is(line, '\n');
357 if (last)
358 *last = '\0';
359 }
360 358
361 /* 2.6.15 may report lines like "... @/tmp/fam-user-^@^@^@^@^@^@^@..." 359 /* 2.6.15 may report lines like "... @/tmp/fam-user-^@^@^@^@^@^@^@..."
362 * (those ^@ are NUL bytes). fgets sees them as tons of empty lines. */ 360 * Other users report long lines filled by NUL bytes.
361 * (those ^@ are NUL bytes too). We see them as empty lines. */
363 if (!line[0]) 362 if (!line[0])
364 return; 363 return;
365 364
@@ -474,20 +473,14 @@ static void do_info(const char *file, const char *name, void (*proc)(int, char *
474 return; 473 return;
475 } 474 }
476 lnr = 0; 475 lnr = 0;
477 do { 476 /* Why? because xmalloc_fgets_str doesn't stop on NULs */
478 buffer = xmalloc_fgets(procinfo); 477 while ((buffer = xmalloc_fgets_str(procinfo, "\n")) != NULL) {
479 if (buffer) { 478 (proc)(lnr++, buffer);
480 (proc)(lnr++, buffer); 479 free(buffer);
481 free(buffer); 480 }
482 }
483 } while (buffer);
484 fclose(procinfo); 481 fclose(procinfo);
485} 482}
486 483
487/*
488 * Our main function.
489 */
490
491int netstat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 484int netstat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
492int netstat_main(int argc, char **argv) 485int netstat_main(int argc, char **argv)
493{ 486{