From patchwork Fri Jul 19 18:31:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rossier Daniel X-Patchwork-Id: 260317 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 439852C0090 for ; Sat, 20 Jul 2013 04:32:10 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0A50C4A029; Fri, 19 Jul 2013 20:32:08 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J2UHBbCujm+3; Fri, 19 Jul 2013 20:32:07 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AC8214A021; Fri, 19 Jul 2013 20:32:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 22D8E4A021 for ; Fri, 19 Jul 2013 20:32:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WT-UDCmU8K98 for ; Fri, 19 Jul 2013 20:31:59 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from heig-vd.ch (mailcl0.heig-vd.ch [193.134.216.181]) by theia.denx.de (Postfix) with ESMTP id 634234A020 for ; Fri, 19 Jul 2013 20:31:53 +0200 (CEST) Received: from [10.192.41.59] (helo=EINTFEA.einet.ad.eivd.ch) by heig-vd.ch stage1 with esmtp (Exim MailCleaner) id 1V0FT6-0006uU-Kn for from ; Fri, 19 Jul 2013 20:31:52 +0200 Received: from EINTMBXC.einet.ad.eivd.ch (10.192.41.65) by EINTMBXA.einet.ad.eivd.ch (10.192.41.63) with Microsoft SMTP Server (TLS) id 15.0.620.29; Fri, 19 Jul 2013 20:31:45 +0200 Received: from EINTMBXC.einet.ad.eivd.ch ([fe80::2947:a03e:6efe:8c49]) by EINTMBXC.einet.ad.eivd.ch ([fe80::2947:a03e:6efe:8c49%23]) with mapi id 15.00.0620.020; Fri, 19 Jul 2013 20:31:45 +0200 X-MailCleaner-SPF: softfail From: Rossier Daniel To: "u-boot@lists.denx.de" Thread-Topic: [PATCH] fixing wrong termination of string Thread-Index: Ac6ErahCPu0S2KMEQ0iKhhV15k8YmA== Date: Fri, 19 Jul 2013 18:31:44 +0000 Message-ID: <2026242272ea4f6bb96adbd87ca61532@EINTMBXC.einet.ad.eivd.ch> Accept-Language: fr-FR, fr-CH, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.192.18.167] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.11 Subject: [U-Boot] [PATCH] fixing wrong termination of string X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hi, I discovered a small bug in lib/vsprintf.c which leads to an "Access violation(2)" when I tried to tftp a file, in QEMU. If CONFIG_SYS_VSNPRINTF is set, the str pointer is incremented even if str reached the end of string (str == end) because of ADDCH. This leads to a wrong length of string and causes the problem. Here is the patch: Regards Daniel HEIG-VD Haute Ecole d'Ingénierie et de Gestion du Canton de Vaud School of Business and Engineering Vaud Dr Daniel Rossier Professeur HES Département TIC Institut REDS (Reconfigurable Embedded Digital Systems) Tél. : 0041 24 55 762 69 Mobile : 0041 79 29 254 58 daniel.rossier@heig-vd.ch Route de Cheseaux 1 CH-1401 Yverdon-les-Bains http://www.heig-vd.ch [Annonce HEIG-VD] diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 82e5c13..2ba8126 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -747,8 +747,9 @@ repeat: #ifdef CONFIG_SYS_VSNPRINTF if (size > 0) { - ADDCH(str, '\0'); - if (str > end) + if (str < end) + *str = '\0'; + else end[-1] = '\0'; } #else