diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-08 16:09:45 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-08 16:09:45 +0100 |
commit | 866710a05616be518d9d32261b52c9f81a025fe1 (patch) | |
tree | a0e37831c32f0fa9f373714b5f79a90d837efdbd | |
parent | 8cd04d1cb658227d3c6eeb2a377314ca9cdf249d (diff) | |
download | busybox-w32-866710a05616be518d9d32261b52c9f81a025fe1.tar.gz busybox-w32-866710a05616be518d9d32261b52c9f81a025fe1.tar.bz2 busybox-w32-866710a05616be518d9d32261b52c9f81a025fe1.zip |
nc: fix "nc -nl -p LPORT RHOST" case (was expecting remote port 0). closes bug 837
function old new delta
dolisten 742 830 +88
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/nc_bloaty.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 9d7c23dee..e14d512ed 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -340,16 +340,29 @@ create new one, and bind() it. TODO */ | |||
340 | rr = accept(netfd, &remend.u.sa, &remend.len); | 340 | rr = accept(netfd, &remend.u.sa, &remend.len); |
341 | if (rr < 0) | 341 | if (rr < 0) |
342 | bb_perror_msg_and_die("accept"); | 342 | bb_perror_msg_and_die("accept"); |
343 | if (themaddr && memcmp(&remend.u.sa, &themaddr->u.sa, remend.len) != 0) { | 343 | if (themaddr) { |
344 | /* nc 1.10 bails out instead, and its error message | 344 | int sv_port, port, r; |
345 | * is not suppressed by o_verbose */ | 345 | |
346 | if (o_verbose) { | 346 | sv_port = get_nport(&remend.u.sa); /* save */ |
347 | char *remaddr = xmalloc_sockaddr2dotted(&remend.u.sa); | 347 | port = get_nport(&themaddr->u.sa); |
348 | bb_error_msg("connect from wrong ip/port %s ignored", remaddr); | 348 | if (port == 0) { |
349 | free(remaddr); | 349 | /* "nc -nl -p LPORT RHOST" (w/o RPORT!): |
350 | * we should accept any remote port */ | ||
351 | set_nport(&remend, 0); /* blot out remote port# */ | ||
352 | } | ||
353 | r = memcmp(&remend.u.sa, &themaddr->u.sa, remend.len); | ||
354 | set_nport(&remend, sv_port); /* restore */ | ||
355 | if (r != 0) { | ||
356 | /* nc 1.10 bails out instead, and its error message | ||
357 | * is not suppressed by o_verbose */ | ||
358 | if (o_verbose) { | ||
359 | char *remaddr = xmalloc_sockaddr2dotted(&remend.u.sa); | ||
360 | bb_error_msg("connect from wrong ip/port %s ignored", remaddr); | ||
361 | free(remaddr); | ||
362 | } | ||
363 | close(rr); | ||
364 | goto again; | ||
350 | } | 365 | } |
351 | close(rr); | ||
352 | goto again; | ||
353 | } | 366 | } |
354 | unarm(); | 367 | unarm(); |
355 | } else | 368 | } else |