From owner-freebsd-bugs Sat Jan 4 11: 0:18 2003 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 8423E37B406 for ; Sat, 4 Jan 2003 11:00:14 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7502943EC5 for ; Sat, 4 Jan 2003 11:00:13 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h04J0DNS041111 for ; Sat, 4 Jan 2003 11:00:13 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h04J0D7J041110; Sat, 4 Jan 2003 11:00:13 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A8E8837B401 for ; Sat, 4 Jan 2003 10:56:50 -0800 (PST) Received: from mailgate.rz.uni-karlsruhe.de (mailgate.rz.uni-karlsruhe.de [129.13.64.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id F303243ED4 for ; Sat, 4 Jan 2003 10:56:48 -0800 (PST) (envelope-from p@i609a.hadiko.de) Received: from nce2.hadiko.de (root@hadince2.hadiko.uni-karlsruhe.de [172.20.32.2]) by mailgate.rz.uni-karlsruhe.de with esmtp (Exim 3.36 #1) id 18UtTT-0004Gz-00; Sat, 04 Jan 2003 19:56:47 +0100 Received: from i609a.hadiko.de (hadii609a.hadiko.uni-karlsruhe.de [172.20.49.159]) by nce2.hadiko.de (8.12.3/8.12.3/Debian -4) with ESMTP id h04IukCj004155 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Sat, 4 Jan 2003 19:56:47 +0100 Received: from i609a.hadiko.de (localhost [127.0.0.1]) by i609a.hadiko.de (8.12.6/8.12.6) with ESMTP id h04Iukw3003229 for ; Sat, 4 Jan 2003 19:56:46 +0100 (CET) (envelope-from p@i609a.hadiko.de) Received: (from p@localhost) by i609a.hadiko.de (8.12.6/8.12.6/Submit) id h04Iuk4q003228; Sat, 4 Jan 2003 19:56:46 +0100 (CET) Message-Id: <200301041856.h04Iuk4q003228@i609a.hadiko.de> Date: Sat, 4 Jan 2003 19:56:46 +0100 (CET) From: Philipp Mergenthaler Reply-To: Philipp Mergenthaler To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/46761: buffer overflow by strcpy() in natd's argv handling 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: 46761 >Category: bin >Synopsis: buffer overflow by strcpy() in natd's argv handling >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 Jan 04 11:00:12 PST 2003 >Closed-Date: >Last-Modified: >Originator: Philipp Mergenthaler >Release: FreeBSD 5.0-CURRENT i386 >Organization: University of Karlsruhe, Germany >Environment: System: FreeBSD i609a.hadiko.de 5.0-CURRENT FreeBSD 5.0-CURRENT #618: Tue Dec 31 23:18:58 CET 2002 p@i609a.hadiko.de:/usr/obj/usr/src/sys/I609 i386 >Description: In src/sbin/natd/natd.c:ParseArgs() the command line arguments are asembled into char parmBuf[256], which is then passed to ParseOption(). There it is passed (via char *strValue) to SetupPortRedirect(), SetupProtoRedirect() or SetupAddressRedirect(), respectively. In each of those we have: char buf[128]; [...] strcpy (buf, parms); which copies up to 256 chars into buf. >How-To-Repeat: >Fix: In addition to replacing the strcpy()s with strlcpy() maybe those "magic number" buffer sizes could be replaced with a macro. Index: natd.c =================================================================== RCS file: /ncvs/src/sbin/natd/natd.c,v retrieving revision 1.39 diff -u -r1.39 natd.c --- natd.c 15 Jan 2002 17:07:56 -0000 1.39 +++ natd.c 4 Jan 2003 18:25:57 -0000 @@ -1351,7 +1351,7 @@ int i; struct alias_link *link = NULL; - strcpy (buf, parms); + strlcpy (buf, parms, sizeof(buf)); /* * Extract protocol. */ @@ -1482,7 +1482,7 @@ char* protoName; struct protoent *protoent; - strcpy (buf, parms); + strlcpy (buf, parms, sizeof(buf)); /* * Extract protocol. */ @@ -1536,7 +1536,7 @@ char* serverPool; struct alias_link *link; - strcpy (buf, parms); + strlcpy (buf, parms, sizeof(buf)); /* * Extract local address. */ >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message