From: Rossier Daniel Date: Fri, 19 Jul 2013 18:31:44 +0000 Subject: [U-Boot] [PATCH] fixing wrong termination of string Message-ID: <2026242272ea4f6bb96adbd87ca61532@EINTMBXC.einet.ad.eivd.ch> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@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: 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 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 at heig-vd.ch Route de Cheseaux 1 CH-1401 Yverdon-les-Bains http://www.heig-vd.ch [Annonce HEIG-VD]