Date: Tue, 2 Oct 2001 09:50:02 -0700 (PDT) From: Peter Pentchev <roam@ringlet.net> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/30968: whois client bug w/ .biz Message-ID: <200110021650.f92Go2A81756@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/30968; it has been noted by GNATS. From: Peter Pentchev <roam@ringlet.net> To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/30968: whois client bug w/ .biz Date: Tue, 2 Oct 2001 19:33:33 +0300 On Tue, Oct 02, 2001 at 11:47:49AM -0400, Garrett Wollman wrote: > <<On Tue, 2 Oct 2001 04:20:02 -0700 (PDT), Peter Pentchev <roam@ringlet.net> said: > > > while ((buf = fgetln(sfi, &len)) != NULL) { > > + newbuf = realloc(buf, len + 1); > > You can't do this. The buffer fgetln() returns belongs to stdio (it > may be a pointer into the FILE's buffer). Oh.. oops! :) Guess I didn't read the manpage too carefully, either.. Thanks, here's an updated patch. G'luck, Peter -- Thit sentence is not self-referential because "thit" is not a word. Index: src/usr.bin/whois/whois.c =================================================================== RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v retrieving revision 1.15.2.4 diff -u -r1.15.2.4 whois.c --- src/usr.bin/whois/whois.c 2001/08/02 02:21:24 1.15.2.4 +++ src/usr.bin/whois/whois.c 2001/10/02 21:42:46 @@ -51,6 +51,7 @@ #include <arpa/inet.h> #include <ctype.h> #include <err.h> +#include <errno.h> #include <netdb.h> #include <stdarg.h> #include <stdio.h> @@ -243,7 +244,7 @@ { FILE *sfi, *sfo; struct addrinfo *res2; - char *buf, *nhost, *p; + char *abuf, *buf, *nhost, *p; int i, nomatch, s; size_t len; @@ -267,6 +268,16 @@ nhost = NULL; nomatch = 0; while ((buf = fgetln(sfi, &len)) != NULL) { + abuf = NULL; + if ((len == 0) || !isspace(buf[len - 1])) { + abuf = calloc(1, len + 1); + if (abuf == NULL) { + errno = ENOMEM; + err(1, "reallocating"); + } + memcpy(abuf, buf, len); + buf = abuf; + } while (len && isspace(buf[len - 1])) buf[--len] = '\0'; @@ -296,6 +307,7 @@ nomatch = 1; } printf("%s\n", buf); + free(abuf); } /* Do second lookup as needed. */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110021650.f92Go2A81756>