diff options
| author | deraadt <> | 1997-04-07 19:55:26 +0000 |
|---|---|---|
| committer | deraadt <> | 1997-04-07 19:55:26 +0000 |
| commit | 4e76ec3d9609041673c88a6227b76069612bbc08 (patch) | |
| tree | 621d027dc648fec2bedb7abe1d3a9bbbda105949 /src | |
| parent | 360d6bc4fd944abd29beaa7eded787677be7234b (diff) | |
| download | openbsd-4e76ec3d9609041673c88a6227b76069612bbc08.tar.gz openbsd-4e76ec3d9609041673c88a6227b76069612bbc08.tar.bz2 openbsd-4e76ec3d9609041673c88a6227b76069612bbc08.zip | |
paranoid about MAXHOSTNAMELEN
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index f6c10424a7..bb0b30749d 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -86,10 +86,6 @@ | |||
| 86 | #ifndef INADDR_NONE | 86 | #ifndef INADDR_NONE |
| 87 | #define INADDR_NONE 0xffffffff | 87 | #define INADDR_NONE 0xffffffff |
| 88 | #endif | 88 | #endif |
| 89 | #ifdef MAXHOSTNAMELEN | ||
| 90 | #undef MAXHOSTNAMELEN /* might be too small on aix, so fix it */ | ||
| 91 | #endif | ||
| 92 | #define MAXHOSTNAMELEN 256 | ||
| 93 | 89 | ||
| 94 | struct host_poop { | 90 | struct host_poop { |
| 95 | char name[MAXHOSTNAMELEN]; /* dns name */ | 91 | char name[MAXHOSTNAMELEN]; /* dns name */ |
| @@ -370,11 +366,13 @@ HINF * gethostpoop (name, numeric) | |||
| 370 | if (! hostent) | 366 | if (! hostent) |
| 371 | /* failure to look up a name is fatal, since we can't do anything with it */ | 367 | /* failure to look up a name is fatal, since we can't do anything with it */ |
| 372 | bail ("%s: forward host lookup failed: ", name); | 368 | bail ("%s: forward host lookup failed: ", name); |
| 373 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2); | 369 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 1); |
| 370 | poop->name[MAXHOSTNAMELEN - 1] = '\0'; | ||
| 374 | for (x = 0; hostent->h_addr_list[x] && (x < 8); x++) { | 371 | for (x = 0; hostent->h_addr_list[x] && (x < 8); x++) { |
| 375 | memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA)); | 372 | memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA)); |
| 376 | strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]), | 373 | strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]), |
| 377 | sizeof (poop->addrs[0])); | 374 | sizeof (poop->addrs[0])-1); |
| 375 | poop->addrs[x][sizeof (poop->addrs[0]) - 1] = '\0'; | ||
| 378 | } /* for x -> addrs, part A */ | 376 | } /* for x -> addrs, part A */ |
| 379 | if (! o_verbose) /* if we didn't want to see the */ | 377 | if (! o_verbose) /* if we didn't want to see the */ |
| 380 | return (poop); /* inverse stuff, we're done. */ | 378 | return (poop); /* inverse stuff, we're done. */ |
| @@ -392,7 +390,8 @@ HINF * gethostpoop (name, numeric) | |||
| 392 | 390 | ||
| 393 | } else { /* not INADDR_NONE: numeric addresses... */ | 391 | } else { /* not INADDR_NONE: numeric addresses... */ |
| 394 | memcpy (poop->iaddrs, &iaddr, sizeof (IA)); | 392 | memcpy (poop->iaddrs, &iaddr, sizeof (IA)); |
| 395 | strncpy (poop->addrs[0], inet_ntoa (iaddr), sizeof (poop->addrs)); | 393 | strncpy (poop->addrs[0], inet_ntoa (iaddr), sizeof (poop->addrs)-1); |
| 394 | poop->addrs[0][sizeof (poop->addrs)-1] = '\0'; | ||
| 396 | if (numeric) /* if numeric-only, we're done */ | 395 | if (numeric) /* if numeric-only, we're done */ |
| 397 | return (poop); | 396 | return (poop); |
| 398 | if (! o_verbose) /* likewise if we don't want */ | 397 | if (! o_verbose) /* likewise if we don't want */ |
| @@ -402,7 +401,8 @@ HINF * gethostpoop (name, numeric) | |||
| 402 | if (! hostent) | 401 | if (! hostent) |
| 403 | holler ("%s: inverse host lookup failed: ", name); | 402 | holler ("%s: inverse host lookup failed: ", name); |
| 404 | else { | 403 | else { |
| 405 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2); | 404 | strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 1); |
| 405 | poop->name[MAXHOSTNAMELEN-1] = '\0'; | ||
| 406 | hostent = gethostbyname (poop->name); | 406 | hostent = gethostbyname (poop->name); |
| 407 | if ((! hostent) || (! hostent->h_addr_list[0])) | 407 | if ((! hostent) || (! hostent->h_addr_list[0])) |
| 408 | holler ("Warning: forward host lookup failed for %s: ", | 408 | holler ("Warning: forward host lookup failed for %s: ", |
| @@ -452,7 +452,8 @@ USHORT getportpoop (pstring, pnum) | |||
| 452 | y = ntohs (servent->s_port); | 452 | y = ntohs (servent->s_port); |
| 453 | if (x != y) /* "never happen" */ | 453 | if (x != y) /* "never happen" */ |
| 454 | holler ("Warning: port-bynum mismatch, %d != %d", x, y); | 454 | holler ("Warning: port-bynum mismatch, %d != %d", x, y); |
| 455 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)); | 455 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)-1); |
| 456 | portpoop->name[sizeof (portpoop->name)-1] = '\0'; | ||
| 456 | } /* if servent */ | 457 | } /* if servent */ |
| 457 | goto gp_finish; | 458 | goto gp_finish; |
| 458 | } /* if pnum */ | 459 | } /* if pnum */ |
| @@ -471,7 +472,8 @@ USHORT getportpoop (pstring, pnum) | |||
| 471 | return (0); | 472 | return (0); |
| 472 | servent = getservbyname (pstring, whichp); | 473 | servent = getservbyname (pstring, whichp); |
| 473 | if (servent) { | 474 | if (servent) { |
| 474 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)); | 475 | strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name)-1); |
| 476 | portpoop->name[sizeof (portpoop->name)-1] = '\0'; | ||
| 475 | x = ntohs (servent->s_port); | 477 | x = ntohs (servent->s_port); |
| 476 | goto gp_finish; | 478 | goto gp_finish; |
| 477 | } /* if servent */ | 479 | } /* if servent */ |
