Nmap Development mailing list archives

[PATCH] Check 'left' in STRAPP() before va_* and vsnprintf()


From: Kris Katterjohn <kjak () ispwest com>
Date: Thu, 07 Sep 2006 12:24:48 -0500

The attached patch checks the variable 'left' before any va_ functions
or vsnprintf() so that they don't have to be called if 'left <= 0'.
Instead of calling vsnprintf() with the "n" argument being 0 which
writes nothing and won't help us out any, we just don't call it and
return 'buf' earlier.

The only thing affected besides not calling these functions is that 'bp'
won't be increased by the return value of vsnprintf() (which I assume is
still the length that _would_ have been written even if "n" is 0). But
all that would do is affect the next value of 'left' which would still
be <= 0 so it doesn't matter.

It's a diff against 4.20ALPHA6.

Thanks,
Kris Katterjohn
--- x/utils.cc  2006-08-28 22:26:10.000000000 -0500
+++ y/utils.cc  2006-09-07 12:12:19.000000000 -0500
@@ -725,9 +725,11 @@ static inline char* STRAPP(char *fmt, ..
     bp = 0;
     return(buf);
   }
+  if (left <= 0)
+    return (buf);
   va_list ap;
   va_start(ap, fmt);
-  bp += vsnprintf (buf+bp, (left>0 ? left : 0), fmt, ap);
+  bp += vsnprintf (buf+bp, left, fmt, ap);
   va_end(ap);
 
   return(buf);

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: