On Mon, 5 May 2014, Jean-Philippe Ouellet wrote:
> On Mon, May 05, 2014 at 11:12:00AM +1000, Joel Sing wrote:
> > > -   i = 0;
> > >     if (arg->count == 0) {
> > >             arg->count = 20;
> > > -           arg->data = (char **)malloc(sizeof(char *) * arg->count);
> > > +           arg->data = calloc(arg->count, sizeof(char *));
> > >     }
> > > -   for (i = 0; i < arg->count; i++)
> > > -           arg->data[i] = NULL;
> >
> > This one is a change in behaviour - if arg->count is > 0 then previously
> > we zeroed arg->data; now we do not.
>
> This one is calloc, not reallocarray, so unless I'm seriously missing
> something obvious here, it is indeed zero'd, no?

Run the following before and after your change:

#include <stdio.h>
#include <strings.h>

#include <openssl/bio.h>
#include <openssl/conf.h>

#include "apps.h"

BIO *bio_err;
CONF *config;

int
main(int argc, char **argv)
{
        char buf[128] = "-one -two -three -four -five";
        ARGS args;
        int i;

        memset(&args, 0, sizeof(args));

        chopup_args(&args, buf, &argc, &argv);

        for (i = 0; i < args.count; i++)
                printf("%i = %p\n", i, args.data[i]);

        strlcpy(buf, "-one -two", sizeof(buf));

        chopup_args(&args, buf, &argc, &argv);

        for (i = 0; i < args.count; i++)
                printf("%i = %p\n", i, args.data[i]);

}

$ gcc -o chopup chopup.c /usr/src/lib/libssl/src/apps/apps.c -I 
/usr/src/lib/libssl/src/apps -lcrypto
-- 

    "Action without study is fatal. Study without action is futile."
        -- Mary Ritter Beard

Reply via email to