From owner-freebsd-bugs@FreeBSD.ORG Thu Aug 5 08:40:19 2004 Return-Path: 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 532ED16A4CE for ; Thu, 5 Aug 2004 08:40:19 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2874743D5D for ; Thu, 5 Aug 2004 08:40:19 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i758eJfJ042625 for ; Thu, 5 Aug 2004 08:40:19 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i758eJMA042624; Thu, 5 Aug 2004 08:40:19 GMT (envelope-from gnats) Resent-Date: Thu, 5 Aug 2004 08:40:19 GMT Resent-Message-Id: <200408050840.i758eJMA042624@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Herve Masson Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EA50216A4CE for ; Thu, 5 Aug 2004 08:31:11 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DA70743D3F for ; Thu, 5 Aug 2004 08:31:11 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i758VBpx095584 for ; Thu, 5 Aug 2004 08:31:11 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i758VBjM095582; Thu, 5 Aug 2004 08:31:11 GMT (envelope-from nobody) Message-Id: <200408050831.i758VBjM095582@www.freebsd.org> Date: Thu, 5 Aug 2004 08:31:11 GMT From: Herve Masson To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/70022: libfetch uses bad computation leading to memory overflow X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Aug 2004 08:40:19 -0000 >Number: 70022 >Category: misc >Synopsis: libfetch uses bad computation leading to memory overflow >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 05 08:40:18 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Herve Masson >Release: zunobox server (www.netzuno.com) based on FreeBSD 4.9-RELEASE-p2 >Organization: Mindstep Corp. >Environment: FreeBSD bytemill.montpellier.mindstep.com 4.9-RELEASE-p2 FreeBSD 4.9-RELEASE-p2 #0: Thu Mar 4 16:35:01 GMT 2004 root@bytemill.montpellier.mindstep.com:/tmp/bsdobjs/usr/src/sys/ZUNOBOX_DEV i386 >Description: The base64 encoding code as provided in http.c [function _http_base64()] uses the following expression to allocate memory for encoded version of the given string: if ((str = malloc(((l + 2) / 3) * 4)) == NULL) This number does not include space for the terminating \0 byte, which is later inserted in the function. As a consequence, the first byte outside the allocated region is zeroed. >How-To-Repeat: I have never had a problem using command line programs on my BSD system; I noticed it when I ported this code on Windows, which has the memory overflow detection turned on in debug mode. >Fix: Use the following math: if ((str = malloc(1+((l + 2) / 3) * 4)) == NULL) >Release-Note: >Audit-Trail: >Unformatted: