Fix possible intoaV4 1 byte overflow

This commit is contained in:
emanuele-f
2019-08-09 17:02:15 +02:00
parent f73dc61ff8
commit e226f99e4e
+7 -9
View File
@@ -854,8 +854,7 @@ static char* ipProto2Name(u_int16_t proto_id) {
* @brief A faster replacement for inet_ntoa(). * @brief A faster replacement for inet_ntoa().
*/ */
char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) { char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) {
char *cp, *retStr; char *cp;
uint byte;
int n; int n;
cp = &buf[bufLen]; cp = &buf[bufLen];
@@ -863,7 +862,8 @@ char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) {
n = 4; n = 4;
do { do {
byte = addr & 0xff; u_int byte = addr & 0xff;
*--cp = byte % 10 + '0'; *--cp = byte % 10 + '0';
byte /= 10; byte /= 10;
if(byte > 0) { if(byte > 0) {
@@ -872,14 +872,12 @@ char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) {
if(byte > 0) if(byte > 0)
*--cp = byte + '0'; *--cp = byte + '0';
} }
*--cp = '.'; if(n > 1)
*--cp = '.';
addr >>= 8; addr >>= 8;
} while(--n > 0); } while (--n > 0);
/* Convert the string to lowercase */ return(cp);
retStr = (char*)(cp+1);
return(retStr);
} }
/* ********************************** */ /* ********************************** */