apps/speed.c:2283: error: NULL_DEREFERENCE
  pointer `fds` last assigned on line 2273 could be null and is dereferenced at line 2283, column 13.
Showing all 19 steps of the trace


apps/speed.c:2266:1: start of procedure do_multi()
2264.   }
2265.   
2266. > static int do_multi(int multi)
2267.   {
2268.       int n;

apps/speed.c:2271:5: 
2269.       int fd[2];
2270.       int *fds;
2271. >     static char sep[] = ":";
2272.   
2273.       fds = malloc(sizeof(*fds) * multi);

apps/speed.c:2273:5: 
2271.       static char sep[] = ":";
2272.   
2273. >     fds = malloc(sizeof(*fds) * multi);
2274.       for (n = 0; n < multi; ++n) {
2275.           if (pipe(fd) == -1) {

apps/speed.c:2274:10: 
2272.   
2273.       fds = malloc(sizeof(*fds) * multi);
2274. >     for (n = 0; n < multi; ++n) {
2275.           if (pipe(fd) == -1) {
2276.               BIO_printf(bio_err, "pipe failure\n");

apps/speed.c:2274:17: Loop condition is true. Entering loop body
2272.   
2273.       fds = malloc(sizeof(*fds) * multi);
2274.       for (n = 0; n < multi; ++n) {
                        ^
2275.           if (pipe(fd) == -1) {
2276.               BIO_printf(bio_err, "pipe failure\n");

apps/speed.c:2275:13: Taking false branch
2273.       fds = malloc(sizeof(*fds) * multi);
2274.       for (n = 0; n < multi; ++n) {
2275.           if (pipe(fd) == -1) {
                    ^
2276.               BIO_printf(bio_err, "pipe failure\n");
2277.               exit(1);

apps/speed.c:2279:9: 
2277.               exit(1);
2278.           }
2279. >         fflush(stdout);
2280.           (void)BIO_flush(bio_err);
2281.           if (fork()) {

apps/speed.c:2280:15: 
2278.           }
2279.           fflush(stdout);
2280. >         (void)BIO_flush(bio_err);
2281.           if (fork()) {
2282.               close(fd[1]);

crypto/bio/bio_lib.c:331:1: start of procedure BIO_ctrl()
  329.   }
  330.   
  331. > long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
  332.   {
  333.       long ret;

crypto/bio/bio_lib.c:336:9: Taking false branch
  334.       long (*cb) (BIO *, int, const char *, int, long, long);
  335.   
  336.       if (b == NULL)
                 ^
  337.           return (0);
  338.   

crypto/bio/bio_lib.c:339:10: Taking false branch
  337.           return (0);
  338.   
  339.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
                  ^
  340.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  341.           return (-2);

crypto/bio/bio_lib.c:339:33: Taking true branch
  337.           return (0);
  338.   
  339.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
                                         ^
  340.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  341.           return (-2);

crypto/bio/bio_lib.c:340:9: Skipping ERR_put_error(): empty list of specs
  338.   
  339.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
  340.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
                 ^
  341.           return (-2);
  342.       }

crypto/bio/bio_lib.c:341:9: 
  339.       if ((b->method == NULL) || (b->method->ctrl == NULL)) {
  340.           BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
  341. >         return (-2);
  342.       }
  343.   

crypto/bio/bio_lib.c:355:1: return from a call to BIO_ctrl
  353.           ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);
  354.       return (ret);
  355. > }
  356.   
  357.   long BIO_callback_ctrl(BIO *b, int cmd,

apps/speed.c:2280:9: 
2278.           }
2279.           fflush(stdout);
2280. >         (void)BIO_flush(bio_err);
2281.           if (fork()) {
2282.               close(fd[1]);

apps/speed.c:2281:13: Taking true branch
2279.           fflush(stdout);
2280.           (void)BIO_flush(bio_err);
2281.           if (fork()) {
                    ^
2282.               close(fd[1]);
2283.               fds[n] = fd[0];

apps/speed.c:2282:13: 
2280.           (void)BIO_flush(bio_err);
2281.           if (fork()) {
2282. >             close(fd[1]);
2283.               fds[n] = fd[0];
2284.           } else {

apps/speed.c:2283:13: 
2281.           if (fork()) {
2282.               close(fd[1]);
2283. >             fds[n] = fd[0];
2284.           } else {
2285.               close(fd[0]);

static int do_multi(int multi)
{
    int n;
    int fd[2];
    int *fds;
    static char sep[] = ":";
    fds = malloc(sizeof(*fds) * multi);
    for (n = 0; n < multi; ++n) {
        if (pipe(fd) == -1) {
            BIO_printf(bio_err, "pipe failure\n");
            exit(1);
        }
        fflush(stdout);
        (void)BIO_flush(bio_err);
        if (fork()) {
            close(fd[1]);
            fds[n] = fd[0];
        } else {
            close(fd[0]);
            close(1);
            if (dup(fd[1]) == -1) {
                BIO_printf(bio_err, "dup failed\n");
                exit(1);
            }
            close(fd[1]);
            mr = 1;
            usertime = 0;
            free(fds);
            return 0;
        }
        printf("Forked child %d\n", n);
    }
    for (n = 0; n < multi; ++n) {
        FILE *f;
        char buf[1024];
        char *p;
        f = fdopen(fds[n], "r");
        while (fgets(buf, sizeof buf, f)) {
            p = strchr(buf, '\n');
            if (p)
                *p = '\0';
            if (buf[0] != '+') {
                BIO_printf(bio_err, "Don't understand line '%s' from child %d\n",
                        buf, n);
                continue;
            }
            printf("Got: %s from %d\n", buf, n);
            if (strncmp(buf, "+F:", 3) == 0) {
                int alg;
                int j;
                p = buf + 3;
                alg = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                for (j = 0; j < SIZE_NUM; ++j)
                    results[alg][j] += atof(sstrsep(&p, sep));
            } else if (strncmp(buf, "+F2:", 4) == 0) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
                else
                    rsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
                else
                    rsa_results[k][1] = d;
            }
# ifndef OPENSSL_NO_DSA
            else if (strncmp(buf, "+F3:", 4) == 0) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
                else
                    dsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
                else
                    dsa_results[k][1] = d;
            }
# endif
# ifndef OPENSSL_NO_EC
            else if (strncmp(buf, "+F4:", 4) == 0) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdsa_results[k][0] =
                        1 / (1 / ecdsa_results[k][0] + 1 / d);
                else
                    ecdsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdsa_results[k][1] =
                        1 / (1 / ecdsa_results[k][1] + 1 / d);
                else
                    ecdsa_results[k][1] = d;
            }
# endif
# ifndef OPENSSL_NO_EC
            else if (strncmp(buf, "+F5:", 4) == 0) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
                else
                    ecdh_results[k][0] = d;
            }
# endif
            else if (strncmp(buf, "+H:", 3) == 0) {
                ;
            } else
                BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n);
        }
        fclose(f);
    }
    free(fds);
    return 1;
}
['static int do_multi(int multi)\n{\n    int n;\n    int fd[2];\n    int *fds;\n    static char sep[] = ":";\n    fds = malloc(sizeof(*fds) * multi);\n    for (n = 0; n < multi; ++n) {\n        if (pipe(fd) == -1) {\n            BIO_printf(bio_err, "pipe failure\\n");\n            exit(1);\n        }\n        fflush(stdout);\n        (void)BIO_flush(bio_err);\n        if (fork()) {\n            close(fd[1]);\n            fds[n] = fd[0];\n        } else {\n            close(fd[0]);\n            close(1);\n            if (dup(fd[1]) == -1) {\n                BIO_printf(bio_err, "dup failed\\n");\n                exit(1);\n            }\n            close(fd[1]);\n            mr = 1;\n            usertime = 0;\n            free(fds);\n            return 0;\n        }\n        printf("Forked child %d\\n", n);\n    }\n    for (n = 0; n < multi; ++n) {\n        FILE *f;\n        char buf[1024];\n        char *p;\n        f = fdopen(fds[n], "r");\n        while (fgets(buf, sizeof buf, f)) {\n            p = strchr(buf, \'\\n\');\n            if (p)\n                *p = \'\\0\';\n            if (buf[0] != \'+\') {\n                BIO_printf(bio_err, "Don\'t understand line \'%s\' from child %d\\n",\n                        buf, n);\n                continue;\n            }\n            printf("Got: %s from %d\\n", buf, n);\n            if (strncmp(buf, "+F:", 3) == 0) {\n                int alg;\n                int j;\n                p = buf + 3;\n                alg = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                for (j = 0; j < SIZE_NUM; ++j)\n                    results[alg][j] += atof(sstrsep(&p, sep));\n            } else if (strncmp(buf, "+F2:", 4) == 0) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n                else\n                    rsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n                else\n                    rsa_results[k][1] = d;\n            }\n# ifndef OPENSSL_NO_DSA\n            else if (strncmp(buf, "+F3:", 4) == 0) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);\n                else\n                    dsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);\n                else\n                    dsa_results[k][1] = d;\n            }\n# endif\n# ifndef OPENSSL_NO_EC\n            else if (strncmp(buf, "+F4:", 4) == 0) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdsa_results[k][0] =\n                        1 / (1 / ecdsa_results[k][0] + 1 / d);\n                else\n                    ecdsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdsa_results[k][1] =\n                        1 / (1 / ecdsa_results[k][1] + 1 / d);\n                else\n                    ecdsa_results[k][1] = d;\n            }\n# endif\n# ifndef OPENSSL_NO_EC\n            else if (strncmp(buf, "+F5:", 4) == 0) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);\n                else\n                    ecdh_results[k][0] = d;\n            }\n# endif\n            else if (strncmp(buf, "+H:", 3) == 0) {\n                ;\n            } else\n                BIO_printf(bio_err, "Unknown type \'%s\' from child %d\\n", buf, n);\n        }\n        fclose(f);\n    }\n    free(fds);\n    return 1;\n}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n    long ret;\n    long (*cb) (BIO *, int, const char *, int, long, long);\n    if (b == NULL)\n        return (0);\n    if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n        BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n        return (-2);\n    }\n    cb = b->callback;\n    if ((cb != NULL) &&\n        ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))\n        return (ret);\n    ret = b->method->ctrl(b, cmd, larg, parg);\n    if (cb != NULL)\n        ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);\n    return (ret);\n}']