... | ... |
@@ -99,6 +99,10 @@ int main(int argc, char **argv) { |
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
pt = strdup(optget(opts, "config-file")->strarg); |
102 |
+ if (pt == NULL) { |
|
103 |
+ printf("Unable to allocate memory for config file\n"); |
|
104 |
+ return 1; |
|
105 |
+ } |
|
102 | 106 |
if((opts = optparse(pt, 0, NULL, 1, OPT_MILTER, 0, opts)) == NULL) { |
103 | 107 |
printf("%s: cannot parse config file %s\n", argv[0], pt); |
104 | 108 |
free(pt); |
... | ... |
@@ -164,6 +164,10 @@ int main(int argc, char **argv) |
164 | 164 |
/* parse the config file */ |
165 | 165 |
cfgfile = optget(opts, "config-file")->strarg; |
166 | 166 |
pt = strdup(cfgfile); |
167 |
+ if (pt == NULL) { |
|
168 |
+ fprintf(stderr, "ERROR: Unable to allocate memory for config file\n"); |
|
169 |
+ return 1; |
|
170 |
+ } |
|
167 | 171 |
if((opts = optparse(cfgfile, 0, NULL, 1, OPT_CLAMD, 0, opts)) == NULL) { |
168 | 172 |
fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", pt); |
169 | 173 |
free(pt); |
... | ... |
@@ -182,6 +182,8 @@ static int onas_ddd_watch_hierarchy(const char* pathname, size_t len, int fd, ui |
182 | 182 |
|
183 | 183 |
size_t size = len + strlen(curr->dirname) + 2; |
184 | 184 |
char *child_path = (char *) cli_malloc(size); |
185 |
+ if (child_path == NULL) |
|
186 |
+ return CL_EMEM; |
|
185 | 187 |
if (hnode->pathname[len-1] == '/') |
186 | 188 |
snprintf(child_path, --size, "%s%s", hnode->pathname, curr->dirname); |
187 | 189 |
else |
... | ... |
@@ -247,6 +249,8 @@ static int onas_ddd_unwatch_hierarchy(const char* pathname, size_t len, int fd, |
247 | 247 |
|
248 | 248 |
size_t size = len + strlen(curr->dirname) + 2; |
249 | 249 |
char *child_path = (char *) cli_malloc(size); |
250 |
+ if (child_path == NULL) |
|
251 |
+ return CL_EMEM; |
|
250 | 252 |
if (hnode->pathname[len-1] == '/') |
251 | 253 |
snprintf(child_path, --size, "%s%s", hnode->pathname, curr->dirname); |
252 | 254 |
else |
... | ... |
@@ -378,6 +382,8 @@ void *onas_ddd_th(void *arg) { |
378 | 378 |
len = strlen(path); |
379 | 379 |
size_t size = strlen(child) + len + 2; |
380 | 380 |
char *child_path = (char *) cli_malloc(size); |
381 |
+ if (child_path == NULL) |
|
382 |
+ return CL_EMEM; |
|
381 | 383 |
if (path[len-1] == '/') |
382 | 384 |
snprintf(child_path, --size, "%s%s", path, child); |
383 | 385 |
else |
... | ... |
@@ -629,6 +629,8 @@ int onas_ht_rm_hierarchy(struct onas_ht *ht, const char* pathname, size_t len, i |
629 | 629 |
|
630 | 630 |
size_t size = len + strlen(curr->dirname) + 2; |
631 | 631 |
char *child_path = (char *) cli_malloc(size); |
632 |
+ if (child_path == NULL) |
|
633 |
+ return CL_EMEM; |
|
632 | 634 |
if (hnode->pathname[len-1] == '/') |
633 | 635 |
snprintf(child_path, size, "%s%s", hnode->pathname, curr->dirname); |
634 | 636 |
else |
... | ... |
@@ -618,6 +618,7 @@ static int make_connection_real(const char *soname, conn_t *conn) |
618 | 618 |
struct addrinfo hints, *res=NULL, *p; |
619 | 619 |
int err; |
620 | 620 |
|
621 |
+ OOM_CHECK(pt); |
|
621 | 622 |
conn->tcp = 0; |
622 | 623 |
|
623 | 624 |
#ifndef _WIN32 |
... | ... |
@@ -1088,11 +1089,13 @@ static void parse_stats(conn_t *conn, struct stats *stats, unsigned idx) |
1088 | 1088 |
|
1089 | 1089 |
if (!conn->version) { |
1090 | 1090 |
stats->engine_version = strdup("???"); |
1091 |
+ OOM_CHECK(stats->engine_version); |
|
1091 | 1092 |
return; |
1092 | 1093 |
} |
1093 | 1094 |
p = pstart = vstart = strchr(conn->version, ' '); |
1094 | 1095 |
if (!vstart) { |
1095 | 1096 |
stats->engine_version = strdup("???"); |
1097 |
+ OOM_CHECK(stats->engine_version); |
|
1096 | 1098 |
return; |
1097 | 1099 |
} |
1098 | 1100 |
/* find digit in version */ |
... | ... |
@@ -1116,6 +1119,7 @@ static void parse_stats(conn_t *conn, struct stats *stats, unsigned idx) |
1116 | 1116 |
pstart = strchr(p, '/'); |
1117 | 1117 |
if (!pstart) |
1118 | 1118 |
stats->db_version = strdup("????"); |
1119 |
+ OOM_CHECK(stats->db_version); |
|
1119 | 1120 |
else { |
1120 | 1121 |
pstart++; |
1121 | 1122 |
p = strchr(pstart, '/'); |
... | ... |
@@ -79,6 +79,10 @@ char *freshdbdir(void) |
79 | 79 |
if((opt = optget(opts, "DatabaseDirectory"))->enabled) { |
80 | 80 |
if(strcmp(dbdir, opt->strarg)) { |
81 | 81 |
char *daily = (char *) malloc(strlen(opt->strarg) + strlen(dbdir) + 30); |
82 |
+ if (daily == NULL) { |
|
83 |
+ fprintf(stderr, "Unable to allocate memory for db directory...\n"); |
|
84 |
+ return NULL; |
|
85 |
+ } |
|
82 | 86 |
sprintf(daily, "%s"PATHSEP"daily.cvd", opt->strarg); |
83 | 87 |
if(access(daily, R_OK)) |
84 | 88 |
sprintf(daily, "%s"PATHSEP"daily.cld", opt->strarg); |