git-svn: trunk@3964
Tomasz Kojm authored on 2008/07/16 23:55:53... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Wed Jul 16 16:33:08 CEST 2008 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamd: improve handling of memory errors |
|
4 |
+ |
|
1 | 5 |
Wed Jul 16 13:56:21 CEST 2008 (tk) |
2 | 6 |
---------------------------------- |
3 | 7 |
* freshclam: if all mirrors get blacklisted internally and freshclam is |
... | ... |
@@ -109,32 +109,35 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru |
109 | 109 |
|
110 | 110 |
cmd = strdup(cpt->strarg); |
111 | 111 |
|
112 |
- if((pt = strstr(cmd, "%v"))) { |
|
112 |
+ if(cmd && (pt = strstr(cmd, "%v"))) { |
|
113 | 113 |
buffer = (char *) malloc(strlen(cmd) + strlen(virname) + 10); |
114 |
- *pt = 0; pt += 2; |
|
115 |
- strcpy(buffer, cmd); |
|
116 |
- strcat(buffer, virname); |
|
117 |
- strcat(buffer, pt); |
|
118 |
- free(cmd); |
|
119 |
- cmd = strdup(buffer); |
|
120 |
- free(buffer); |
|
114 |
+ if(buffer) { |
|
115 |
+ *pt = 0; pt += 2; |
|
116 |
+ strcpy(buffer, cmd); |
|
117 |
+ strcat(buffer, virname); |
|
118 |
+ strcat(buffer, pt); |
|
119 |
+ free(cmd); |
|
120 |
+ cmd = strdup(buffer); |
|
121 |
+ free(buffer); |
|
122 |
+ } |
|
121 | 123 |
} |
122 | 124 |
|
123 | 125 |
/* Allocate env vars.. to be portable env vars should not be freed */ |
124 | 126 |
buffer = (char *) malloc(strlen(ENV_FILE) + strlen(filename) + 2); |
125 |
- sprintf(buffer, "%s=%s", ENV_FILE, filename); |
|
126 |
- putenv(buffer); |
|
127 |
+ if(buffer) { |
|
128 |
+ sprintf(buffer, "%s=%s", ENV_FILE, filename); |
|
129 |
+ putenv(buffer); |
|
130 |
+ } |
|
127 | 131 |
|
128 | 132 |
buffer = (char *) malloc(strlen(ENV_VIRUS) + strlen(virname) + 2); |
129 |
- sprintf(buffer, "%s=%s", ENV_VIRUS, virname); |
|
130 |
- putenv(buffer); |
|
131 |
- |
|
133 |
+ if(buffer) { |
|
134 |
+ sprintf(buffer, "%s=%s", ENV_VIRUS, virname); |
|
135 |
+ putenv(buffer); |
|
136 |
+ } |
|
132 | 137 |
/* WARNING: this is uninterruptable ! */ |
133 |
- exit(system(cmd)); |
|
138 |
+ if(cmd) |
|
139 |
+ exit(system(cmd)); |
|
134 | 140 |
|
135 |
- /* The below is not reached but is here for completeness to remind |
|
136 |
- maintainers that this buffer is still allocated.. */ |
|
137 |
- free(cmd); |
|
138 | 141 |
} else if (pid > 0) { |
139 | 142 |
/* parent */ |
140 | 143 |
waitpid(pid, NULL, 0); |
... | ... |
@@ -480,12 +480,13 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne |
480 | 480 |
pthread_attr_setdetachstate(&clamuko_attr, PTHREAD_CREATE_JOINABLE); |
481 | 481 |
|
482 | 482 |
tharg = (struct thrarg *) malloc(sizeof(struct thrarg)); |
483 |
- tharg->copt = copt; |
|
484 |
- tharg->engine = engine; |
|
485 |
- tharg->limits = &limits; |
|
486 |
- tharg->options = options; |
|
487 |
- |
|
488 |
- pthread_create(&clamuko_pid, &clamuko_attr, clamukoth, tharg); |
|
483 |
+ if(tharg) { |
|
484 |
+ tharg->copt = copt; |
|
485 |
+ tharg->engine = engine; |
|
486 |
+ tharg->limits = &limits; |
|
487 |
+ tharg->options = options; |
|
488 |
+ pthread_create(&clamuko_pid, &clamuko_attr, clamukoth, tharg); |
|
489 |
+ } else logg("!Not enough memory to start Clamuko\n"); |
|
489 | 490 |
} |
490 | 491 |
#else |
491 | 492 |
logg("Clamuko is not available.\n"); |
... | ... |
@@ -589,18 +590,28 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne |
589 | 589 |
|
590 | 590 |
if (!progexit && new_sd >= 0) { |
591 | 591 |
client_conn = (client_conn_t *) malloc(sizeof(struct client_conn_tag)); |
592 |
- client_conn->sd = new_sd; |
|
593 |
- client_conn->options = options; |
|
594 |
- client_conn->copt = copt; |
|
595 |
- client_conn->engine = cl_dup(engine); |
|
596 |
- client_conn->engine_timestamp = reloaded_time; |
|
597 |
- client_conn->limits = &limits; |
|
598 |
- client_conn->socketds = socketds; |
|
599 |
- client_conn->nsockets = nsockets; |
|
600 |
- if (!thrmgr_dispatch(thr_pool, client_conn)) { |
|
601 |
- closesocket(client_conn->sd); |
|
602 |
- free(client_conn); |
|
603 |
- logg("!thread dispatch failed\n"); |
|
592 |
+ if(client_conn) { |
|
593 |
+ client_conn->sd = new_sd; |
|
594 |
+ client_conn->options = options; |
|
595 |
+ client_conn->copt = copt; |
|
596 |
+ client_conn->engine = cl_dup(engine); |
|
597 |
+ client_conn->engine_timestamp = reloaded_time; |
|
598 |
+ client_conn->limits = &limits; |
|
599 |
+ client_conn->socketds = socketds; |
|
600 |
+ client_conn->nsockets = nsockets; |
|
601 |
+ if(!thrmgr_dispatch(thr_pool, client_conn)) { |
|
602 |
+ closesocket(client_conn->sd); |
|
603 |
+ free(client_conn); |
|
604 |
+ logg("!thread dispatch failed\n"); |
|
605 |
+ } |
|
606 |
+ } else { |
|
607 |
+ logg("!Can't allocate memory for client_conn\n"); |
|
608 |
+ closesocket(new_sd); |
|
609 |
+ if(cfgopt(copt, "ExitOnOOM")->enabled) { |
|
610 |
+ pthread_mutex_lock(&exit_mutex); |
|
611 |
+ progexit = 1; |
|
612 |
+ pthread_mutex_unlock(&exit_mutex); |
|
613 |
+ } |
|
604 | 614 |
} |
605 | 615 |
} |
606 | 616 |
|