[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2] lib/nolibc: Fix vsnprintf when size is zero



Modified PCHAR macro so that it evaluates it's params and updates their values 
every time.
As vsnprintf is firstly called to compute the length of the resulting
string with a size equal to zero given as parameter, the PCHAR
macro will not evaluate its decrementing argument since the internal condition 
needs
the size to be greater than two to compute the decrement. Cases like this lead
to infinite loops. To solve this issue a new variable is used before the if 
statement,
forcing any modification to occur.
---
 lib/nolibc/stdio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/nolibc/stdio.c b/lib/nolibc/stdio.c
index 7e3d368..d2637ee 100644
--- a/lib/nolibc/stdio.c
+++ b/lib/nolibc/stdio.c
@@ -101,8 +101,9 @@ int vsnprintf(char *str, size_t size, const char *fmt, 
va_list ap)
 {
 #define PCHAR(c)                                                               
\
        {                                                                      \
+               int cc = (c);                                                  \
                if (size >= 2) {                                               \
-                       *str++ = c;                                            \
+                       *str++ = cc;                                           \
                        size--;                                                \
                }                                                              \
                retval++;                                                      \
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.