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

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



Hi Razvan,

thank you for the update! Patch looks good:

Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>

As discussed off-list, I will update the commit message slightly to clarify and then push this in a bit.

Cheers,
Florian

On 08/21/2018 01:21 PM, Razvan Rotaru wrote:
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++;                                                      \


--
Dr. Florian Schmidt
フローリアン・シュミット
Research Scientist,
Systems and Machine Learning Group
NEC Laboratories Europe
Kurfürsten-Anlage 36, D-69115 Heidelberg
Tel.     +49 (0)6221 4342-265
Fax:     +49 (0)6221 4342-155
e-mail:  florian.schmidt@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

_______________________________________________
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®.