From 061732adf0261ed644d55d8e50c484850846cb92 Mon Sep 17 00:00:00 2001 From: Tatsuhiko Kubo Date: Wed, 15 Apr 2015 09:20:45 +0900 Subject: [PATCH] improved malloc error handlings. --- src/comp_helper.c | 3 +++ src/util.cc | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/comp_helper.c b/src/comp_helper.c index fe8bc2b5..d697c6a0 100644 --- a/src/comp_helper.c +++ b/src/comp_helper.c @@ -57,6 +57,9 @@ json_t *dump_header(const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen) { json_t *nv_pair = json_object(); char *cname = malloc(namelen + 1); + if (cname == NULL) { + return NULL; + } memcpy(cname, name, namelen); cname[namelen] = '\0'; json_object_set_new(nv_pair, cname, json_pack("s#", value, valuelen)); diff --git a/src/util.cc b/src/util.cc index d08d8b5b..65d06487 100644 --- a/src/util.cc +++ b/src/util.cc @@ -737,10 +737,16 @@ char *get_exec_path(int argc, char **const argv, const char *cwd) { if (argv0[0] == '/') { path = static_cast(malloc(len + 1)); + if (path == NULL) { + return NULL; + } memcpy(path, argv0, len + 1); } else { auto cwdlen = strlen(cwd); path = static_cast(malloc(len + 1 + cwdlen + 1)); + if (path == NULL) { + return NULL; + } memcpy(path, cwd, cwdlen); path[cwdlen] = '/'; memcpy(path + cwdlen + 1, argv0, len + 1);