From owner-freebsd-bugs Sat Aug 3 10: 0:18 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 38CFC37B400 for ; Sat, 3 Aug 2002 10:00:13 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id EC2AE43E70 for ; Sat, 3 Aug 2002 10:00:11 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g73H0BJU010076 for ; Sat, 3 Aug 2002 10:00:11 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g73H0B4r010075; Sat, 3 Aug 2002 10:00:11 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D1FAC37B400 for ; Sat, 3 Aug 2002 09:57:54 -0700 (PDT) Received: from fafoe.dyndns.org (chello212186121237.14.vie.surfer.at [212.186.121.237]) by mx1.FreeBSD.org (Postfix) with ESMTP id 586C343E3B for ; Sat, 3 Aug 2002 09:57:54 -0700 (PDT) (envelope-from stefan@fafoe.dyndns.org) Received: by frog.fafoe (Postfix, from userid 1001) id 0FE86281; Sat, 3 Aug 2002 19:02:55 +0200 (CEST) Message-Id: <20020803170255.0FE86281@frog.fafoe> Date: Sat, 3 Aug 2002 19:02:55 +0200 (CEST) From: Stefan Farfeleder Reply-To: Stefan Farfeleder To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: misc/41289: inet_ntop(3) buffer overflow 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 >Number: 41289 >Category: misc >Synopsis: inet_ntop(3) buffer overflow >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Aug 03 10:00:11 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Stefan Farfeleder >Release: FreeBSD 4.6-STABLE i386 >Organization: >Environment: System: FreeBSD frog.fafoe 4.6-STABLE FreeBSD 4.6-STABLE #0: Fri Aug 2 01:04:34 CEST 2002 freebsd@frog.fafoe:/freebsd/stable/obj/freebsd/stable/src/sys/FROG i386 >Description: inet_ntop4()'s check for ENOSPC is wrong. sprintf() doesn't include the terminating '\0' in its return value. inet_ntop6() seems safe. >How-To-Repeat: Script started on Sat Aug 3 18:57:36 2002 stefan@frog:~ 501 (0)$ cat pr.c #include #include #include #include #include int main(void) { char buf[8]; u_int32_t i = inet_addr("1.2.3.4"); buf[7] = 1; inet_ntop(AF_INET, &i, buf, 7); if (buf[7] != 1) printf("buf[7] overwritten!\n"); return 0; } stefan@frog:~ 502 (0)$ c89 pr.c stefan@frog:~ 503 (0)$ ./a.out buf[7] overwritten! stefan@frog:~ 504 (0)$ exit Script done on Sat Aug 3 18:57:52 2002 >Fix: --- inet_ntop.c.orig Sat Aug 3 18:14:52 2002 +++ inet_ntop.c Sat Aug 3 18:41:33 2002 @@ -85,7 +85,7 @@ static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; - if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) { + if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) { errno = ENOSPC; return (NULL); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message