mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 14:39:02 +00:00
Adding Snprintf() and Vsnprintf() to nbase/nbase_str.c. This is because of Windows' stupid implementation where it doesn't write a NULL byte at the end of the buffer if the result is truncated. I would've just #defined snprintf and vsnprintf to some wrapper function for Windows, but this doesn't work as libdnet and libpcap (and libpcap includes under mswin32) define snprintf to _snprintf and vsnprintf to _vsnprintf like we do, and through the many defines they end up being available in the Nmap sources. Vsnprintf() uses vsnprintf() (and writes a NULL byte at the end if truncated), and Snprintf uses Vsnprintf().
This commit is contained in:
10
utils.cc
10
utils.cc
@@ -745,19 +745,19 @@ void bintohexstr(char *buf, int buflen, char *src, int srclen){
|
||||
int bp=0;
|
||||
int i;
|
||||
for(i=0; i<srclen; i++){
|
||||
bp += snprintf(buf+bp, buflen-bp, "\\x%02hhx",src[i]);
|
||||
bp += Snprintf(buf+bp, buflen-bp, "\\x%02hhx",src[i]);
|
||||
if(bp >= buflen)break;
|
||||
if(i%16==7){
|
||||
bp += snprintf(buf+bp, buflen-bp," ");
|
||||
bp += Snprintf(buf+bp, buflen-bp," ");
|
||||
if(bp >= buflen)break;
|
||||
}
|
||||
if(i%16==15){
|
||||
bp += snprintf(buf+bp, buflen-bp,"\n");
|
||||
bp += Snprintf(buf+bp, buflen-bp,"\n");
|
||||
if(bp >= buflen)break;
|
||||
}
|
||||
}
|
||||
if(i%16!=0 && bp < buflen)
|
||||
bp += snprintf(buf+bp, buflen-bp,"\n");
|
||||
bp += Snprintf(buf+bp, buflen-bp,"\n");
|
||||
}
|
||||
|
||||
static inline char* STRAPP(char *fmt, ...) {
|
||||
@@ -772,7 +772,7 @@ static inline char* STRAPP(char *fmt, ...) {
|
||||
return buf;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
bp += vsnprintf (buf+bp, left, fmt, ap);
|
||||
bp += Vsnprintf (buf+bp, left, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return(buf);
|
||||
|
||||
Reference in New Issue
Block a user