]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
In muted.c, check the return value of strdup. In ael_main.c, check the return
authorRussell Bryant <russell@russellbryant.com>
Tue, 24 Oct 2006 01:27:42 +0000 (01:27 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 24 Oct 2006 01:27:42 +0000 (01:27 +0000)
value of calloc.  (issue #8157)

In passing fix a few minor bugs in ael_main.c.  The last argument to strncpy()
was a hard-coded 100, where it should have been 99.  I changed this to use
sizeof() - 1.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@46067 65c4cc65-6c06-0410-ace0-fbb531ad65f3

utils/ael_main.c
utils/muted.c

index 225e23b91907abac729b3d8fa0a8c063d524b146..606ac8d6a6d17dab8aa8af9669d3f787044e8a85 100644 (file)
@@ -62,8 +62,10 @@ void destroy_namelist(struct namelist *x)
 struct namelist *create_name(char *name);
 struct namelist *create_name(char *name)
 {
-       struct namelist *x = (struct namelist *)calloc(sizeof(struct namelist),1);
-       strncpy(x->name,name,100);
+       struct namelist *x = calloc(1, sizeof(*x));
+       if (!x)
+               return NULL;
+       strncpy(x->name, name, sizeof(x->name) - 1);
        return x;
 }
 
@@ -253,14 +255,16 @@ void pbx_builtin_setvar(void *chan, void *data)
 
 struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
 {
-       struct ast_context *x = (struct ast_context *)calloc(sizeof(struct ast_context),1);
+       struct ast_context *x = calloc(1, sizeof(*x));
+       if (!x)
+               return NULL;
        x->next = context_list;
        context_list = x;
-       if(!no_comp)
+       if (!no_comp)
                printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
        conts++;
-       strncpy(x->name,name,100);
-       strncpy(x->registrar,registrar,100);
+       strncpy(x->name, name, sizeof(x->name) - 1);
+       strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
        return x;
 }
 
index 6a0912fdbf1f8889aa71e96e81ff5a42d791af5d..37ae42c5ef1c216be4e7aeaeed54948cf4bf0008 100644 (file)
@@ -85,8 +85,15 @@ static void add_channel(char *tech, char *location)
        chan = malloc(sizeof(struct channel));
        if (chan) {
                memset(chan, 0, sizeof(struct channel));
-               chan->tech = strdup(tech);
-               chan->location = strdup(location);
+               if (!(chan->tech = strdup(tech))) {
+                       free(chan);
+                       return;
+               }
+               if (!(chan->location = strdup(location))) {
+                       free(chan->tech);
+                       free(chan);
+                       return;
+               }
                chan->next = channels;
                channels = chan;
        }
@@ -550,7 +557,10 @@ static void append_sub(struct channel *chan, char *name)
        sub = malloc(sizeof(struct subchannel));
        if (sub) {
                memset(sub, 0, sizeof(struct subchannel));
-               sub->name = strdup(name);
+               if (!(sub->name = strdup(name))) {
+                       free(sub);
+                       return;
+               }
                sub->next = chan->subs;
                chan->subs = sub;
        }