From bd851bab8f024674b62a3114859922a5f6759956 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Tue, 11 Dec 2012 20:59:58 +0000 Subject: [PATCH] ID: 3594835 - NULL reference possible in str2*() functions Commit fixes possible NULL reference in str2*() functions in 'lib/helper.c'. Although it's less likely to happen in ipmitool's daily life, it's still possible. Let's make sure it doesn't happen. --- ipmitool/lib/helper.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ipmitool/lib/helper.c b/ipmitool/lib/helper.c index d3ec1bc..73df753 100644 --- a/ipmitool/lib/helper.c +++ b/ipmitool/lib/helper.c @@ -211,6 +211,9 @@ int str2int(const char * str, int32_t * int_ptr) { int rc = 0; int64_t arg_long = 0; + if (!str || !int_ptr) + return (-1); + if ( (rc = str2long(str, &arg_long)) != 0 ) { *int_ptr = 0; return rc; @@ -235,6 +238,9 @@ int str2uint(const char * str, uint32_t * uint_ptr) { int rc = 0; uint64_t arg_ulong = 0; + if (!str || !uint_ptr) + return (-1); + if ( (rc = str2ulong(str, &arg_ulong)) != 0) { *uint_ptr = 0; return rc; @@ -259,6 +265,9 @@ int str2short(const char * str, int16_t * shrt_ptr) { int rc = (-3); int64_t arg_long = 0; + if (!str || !shrt_ptr) + return (-1); + if ( (rc = str2long(str, &arg_long)) != 0 ) { *shrt_ptr = 0; return rc; @@ -283,6 +292,9 @@ int str2ushort(const char * str, uint16_t * ushrt_ptr) { int rc = (-3); uint64_t arg_ulong = 0; + if (!str || !ushrt_ptr) + return (-1); + if ( (rc = str2ulong(str, &arg_ulong)) != 0 ) { *ushrt_ptr = 0; return rc; @@ -307,6 +319,9 @@ int str2uchar(const char * str, uint8_t * uchr_ptr) { int rc = (-3); uint64_t arg_ulong = 0; + if (!str || !uchr_ptr) + return (-1); + if ( (rc = str2ulong(str, &arg_ulong)) != 0 ) { *uchr_ptr = 0; return rc;