summaryrefslogtreecommitdiffstats
path: root/libsysutils
diff options
context:
space:
mode:
authorHong-Mei Li <a21834@motorola.com>2013-04-01 11:24:44 +0800
committerHong-Mei Li <a21834@motorola.com>2013-05-20 17:30:11 +0800
commit544a7f7a36cb9434505fe5cdc9e79d16937ac23f (patch)
tree8fd1d7fd2e5fab789ef12c1b00e51fe70ce479e8 /libsysutils
parentf5562cb66c1c15d65bc372ede4c180430e1ce9d7 (diff)
downloadcore-544a7f7a36cb9434505fe5cdc9e79d16937ac23f.tar.gz
core-544a7f7a36cb9434505fe5cdc9e79d16937ac23f.tar.bz2
core-544a7f7a36cb9434505fe5cdc9e79d16937ac23f.zip
libsysutils: fix null pointer and memory leak issue
In SocketClient::quoteArg function 1. Fix potential null pointer accessing issue 2. Fix potential memory leak introduced by realloc fail Change-Id: I1ca0f9089290d43452e9a71428244545f4ed866b Signed-off-by: Hong-Mei Li <a21834@motorola.com>
Diffstat (limited to 'libsysutils')
-rw-r--r--libsysutils/src/SocketClient.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 3d4984d3b..ae0e0770d 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -112,6 +112,12 @@ char *SocketClient::quoteArg(const char *arg) {
char *result = (char *)malloc(len * 2 + 3);
char *current = result;
const char *end = arg + len;
+ char *oldresult;
+
+ if(result == NULL) {
+ SLOGW("malloc error (%s)", strerror(errno));
+ return NULL;
+ }
*(current++) = '"';
while (arg < end) {
@@ -125,8 +131,9 @@ char *SocketClient::quoteArg(const char *arg) {
}
*(current++) = '"';
*(current++) = '\0';
+ oldresult = result; // save pointer in case realloc fails
result = (char *)realloc(result, current-result);
- return result;
+ return result ? result : oldresult;
}