summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 13:10:04 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-10-12 13:10:04 (GMT)
commit36a0ea60d220a7edc0c83b73ad1867fd347ca77e (patch) (side-by-side diff)
treece6a227382a2d3ec6ca0da05f66cfdf3eb01b2ff /src
parentb6678bb65fce1f64e82cc049aae3d7ba6f8aa19c (diff)
downloadvmod-binlog-36a0ea60d220a7edc0c83b73ad1867fd347ca77e.tar.gz
vmod-binlog-36a0ea60d220a7edc0c83b73ad1867fd347ca77e.tar.bz2
Handle eventual out-of-memory conditions.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/binlog.c2
-rw-r--r--src/pack.c21
2 files changed, 21 insertions, 2 deletions
diff --git a/src/binlog.c b/src/binlog.c
index 6f438a8..b2d9f87 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -209,12 +209,14 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
AN(conf->dir);
conf->inst_head = packcomp(dataspec, &p);
+ AN(conf->inst_head);
if (*p) {
binlog_error("cannot compile data format near %s", p);
abort();
}
conf->recsize = packsize(conf->inst_head);
conf->env = packenv_create(conf->recsize);
+ AN(conf->env);
conf->recsize += offsetof(struct binlog_record,data);
conf->dataspec = strdup(dataspec);
AN(conf->dataspec);
diff --git a/src/pack.c b/src/pack.c
index a6ee933..5594bb1 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -432,6 +432,8 @@ packcomp(const char *s, char **endp)
if (getrep(s + 1, &s, &rep))
break;
pi = malloc(sizeof(*pi));
+ if (!pi)
+ return NULL;
pi->next = NULL;
pi->spec = ps;
pi->rep = rep;
@@ -515,8 +517,14 @@ struct packenv *
packenv_create(size_t size)
{
struct packenv *env = calloc(1, sizeof(*env));
- env->buf_base = calloc(1, size);
- env->buf_size = size;
+ if (env) {
+ env->buf_base = calloc(1, size);
+ if (!env->buf_base) {
+ free(env);
+ return NULL;
+ }
+ env->buf_size = size;
+ }
return env;
}
@@ -565,11 +573,20 @@ main(int argc, char **argv)
abort();
pi = packcomp(argv[0], &end);
+ if (!pi) {
+ fprintf(stderr, "out of memory\n");
+ abort();
+ }
if (*end) {
fprintf(stderr, "compile error near %s\n", end);
exit(1);
}
env = packenv_create(packsize(pi));
+ if (!env) {
+ fprintf(stderr, "out of memory\n");
+ abort();
+ }
+
env->fp = stdout;
env->argv = argv + 1;
env->argc = argc - 1;

Return to:

Send suggestions and report system problems to the System administrator.