diff options
author | emanuele-f <black.silver@hotmail.it> | 2019-08-09 17:02:15 +0200 |
---|---|---|
committer | emanuele-f <black.silver@hotmail.it> | 2019-08-09 17:02:15 +0200 |
commit | e226f99e4e6922b7c8792b93b484d48ce89b298b (patch) | |
tree | 3588bc02316c8b66924dafb5be9d33dfe80e6802 | |
parent | f73dc61ff8e498b8d2ae4ce26ec1de862a48592f (diff) |
Fix possible intoaV4 1 byte overflow
-rw-r--r-- | example/ndpiReader.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index e800391de..dc1d5505d 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -854,8 +854,7 @@ static char* ipProto2Name(u_int16_t proto_id) { * @brief A faster replacement for inet_ntoa(). */ char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) { - char *cp, *retStr; - uint byte; + char *cp; int n; cp = &buf[bufLen]; @@ -863,7 +862,8 @@ char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) { n = 4; do { - byte = addr & 0xff; + u_int byte = addr & 0xff; + *--cp = byte % 10 + '0'; byte /= 10; if(byte > 0) { @@ -872,14 +872,12 @@ char* intoaV4(u_int32_t addr, char* buf, u_int16_t bufLen) { if(byte > 0) *--cp = byte + '0'; } - *--cp = '.'; + if(n > 1) + *--cp = '.'; addr >>= 8; - } while(--n > 0); - - /* Convert the string to lowercase */ - retStr = (char*)(cp+1); + } while (--n > 0); - return(retStr); + return(cp); } /* ********************************** */ |