[U-Boot] [PATCH] fixing wrong termination of string

Rossier Daniel Daniel.Rossier at heig-vd.ch
Fri Jul 19 20:31:44 CEST 2013


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<mailto:daniel.rossier at heig-vd.ch>
Route de Cheseaux 1
CH-1401 Yverdon-les-Bains
http://www.heig-vd.ch<http://www.heig-vd.ch/>
[Annonce HEIG-VD]<http://go.heig-vd.ch/bannerEmail/>



More information about the U-Boot mailing list