From owner-freebsd-bugs Tue Oct 2 9:50:20 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 3C19737B40B for ; Tue, 2 Oct 2001 09:50:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f92Go2A81756; Tue, 2 Oct 2001 09:50:02 -0700 (PDT) (envelope-from gnats) Date: Tue, 2 Oct 2001 09:50:02 -0700 (PDT) Message-Id: <200110021650.f92Go2A81756@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Peter Pentchev Subject: Re: bin/30968: whois client bug w/ .biz Reply-To: Peter Pentchev Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/30968; it has been noted by GNATS. From: Peter Pentchev To: Garrett Wollman 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: > < 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 #include #include +#include #include #include #include @@ -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