apps/rehash.c:481: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `do_dir`.
Showing all 8 steps of the trace


apps/rehash.c:450:17: Call
448.   
449.       prog = opt_init(argc, argv, rehash_options);
450.       while ((o = opt_next()) != OPT_EOF) {
                       ^
451.           switch (o) {
452.           case OPT_EOF:

apps/opt.c:650:9: Assignment
  648.       /* If we have --flag=foo, snip it off */
  649.       if ((arg = strchr(p, '=')) != NULL)
  650.           *arg++ = '\0';
                 ^
  651.       for (o = opts; o->name; ++o) {
  652.           /* If not this option, move on to the next one. */

apps/rehash.c:481:21: Call
479.       if (*argv != NULL) {
480.           while (*argv != NULL)
481.               errs += do_dir(*argv++, h);
                           ^
482.       } else if ((env = getenv(X509_get_default_cert_dir_env())) != NULL) {
483.           char lsc[2] = { LIST_SEPARATOR_CHAR, '\0' };

apps/rehash.c:299:1: Parameter `dirname->strlen`
  297.    * Process a directory; return number of errors found.
  298.    */
  299. > static int do_dir(const char *dirname, enum Hash h)
  300.   {
  301.       BUCKET *bp, *nextbp;

apps/rehash.c:318:27: Call
  316.       }
  317.       buflen = strlen(dirname);
  318.       pathsep = (buflen && !ends_with_dirsep(dirname)) ? "/": "";
                                   ^
  319.       buflen += NAME_MAX + 1 + 1;
  320.       buf = app_malloc(buflen, "filename buffer");

apps/rehash.c:282:1: <LHS trace>
280.   }
281.   
282. > static int ends_with_dirsep(const char *path)
283.   {
284.       if (*path != '\0')

apps/rehash.c:282:1: Parameter `path->strlen`
    280.   }
    281.   
    282. > static int ends_with_dirsep(const char *path)
    283.   {
    284.       if (*path != '\0')

apps/rehash.c:285:9: Binary operation: ([0, +oo] - 1):unsigned64 by call to `do_dir` 
    283.   {
    284.       if (*path != '\0')
    285.           path += strlen(path) - 1;
                   ^
    286.   # if defined __VMS
    287.       if (*path == ']' || *path == '>' || *path == ':')

static int ends_with_dirsep(const char *path)
{
    if (*path != '\0')
        path += strlen(path) - 1;
# if defined __VMS
    if (*path == ']' || *path == '>' || *path == ':')
        return 1;
# elif defined _WIN32
    if (*path == '\\')
        return 1;
# endif
    return *path == '/';
}
['int rehash_main(int argc, char **argv)\n{\n    const char *env, *prog;\n    char *e, *m;\n    int errs = 0;\n    OPTION_CHOICE o;\n    enum Hash h = HASH_NEW;\n    prog = opt_init(argc, argv, rehash_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(rehash_options);\n            goto end;\n        case OPT_COMPAT:\n            h = HASH_BOTH;\n            break;\n        case OPT_OLD:\n            h = HASH_OLD;\n            break;\n        case OPT_N:\n            remove_links = 0;\n            break;\n        case OPT_VERBOSE:\n            verbose = 1;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    evpmd = EVP_sha1();\n    evpmdsize = EVP_MD_size(evpmd);\n    if (*argv != NULL) {\n        while (*argv != NULL)\n            errs += do_dir(*argv++, h);\n    } else if ((env = getenv(X509_get_default_cert_dir_env())) != NULL) {\n        char lsc[2] = { LIST_SEPARATOR_CHAR, \'\\0\' };\n        m = OPENSSL_strdup(env);\n        for (e = strtok(m, lsc); e != NULL; e = strtok(NULL, lsc))\n            errs += do_dir(e, h);\n        OPENSSL_free(m);\n    } else {\n        errs += do_dir(X509_get_default_cert_dir(), h);\n    }\n end:\n    return errs;\n}', 'int opt_next(void)\n{\n    char *p, *estr;\n    const OPTIONS *o;\n    int ival;\n    long lval;\n    unsigned long ulval;\n    ossl_intmax_t imval;\n    ossl_uintmax_t umval;\n#if !defined(_WIN32)\n    char *c;\n    int oerrno;\n#endif\n    arg = NULL;\n    p = argv[opt_index];\n    if (p == NULL)\n        return 0;\n    if (*p != \'-\')\n        return 0;\n    opt_index++;\n    if (strcmp(p, "--") == 0)\n        return 0;\n    if (*++p == \'-\')\n        p++;\n    flag = p - 1;\n    if ((arg = strchr(p, \'=\')) != NULL)\n        *arg++ = \'\\0\';\n    for (o = opts; o->name; ++o) {\n        if (strcmp(p, o->name) != 0)\n            continue;\n        if (o->valtype == 0 || o->valtype == \'-\') {\n            if (arg) {\n                BIO_printf(bio_err,\n                           "%s: Option -%s does not take a value\\n", prog, p);\n                return -1;\n            }\n            return o->retval;\n        }\n        if (arg == NULL) {\n            if (argv[opt_index] == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Option -%s needs a value\\n", prog, o->name);\n                return -1;\n            }\n            arg = argv[opt_index++];\n        }\n        switch (o->valtype) {\n        default:\n        case \'s\':\n            break;\n        case \'/\':\n            if (app_isdir(arg) > 0)\n                break;\n            BIO_printf(bio_err, "%s: Not a directory: %s\\n", prog, arg);\n            return -1;\n        case \'<\':\n            if (strcmp(arg, "-") == 0 || app_access(arg, R_OK) == 0)\n                break;\n            BIO_printf(bio_err,\n                       "%s: Cannot open input file %s, %s\\n",\n                       prog, arg, strerror(errno));\n            return -1;\n        case \'>\':\n#if !defined(_WIN32)\n            c = OPENSSL_strdup(arg);\n            if (c == NULL) {\n                BIO_printf(bio_err,\n                           "%s: Memory allocation failure\\n", prog);\n                return -1;\n            }\n            oerrno = errno;\n            errno = 0;\n            if (strcmp(arg, "-") == 0\n                || (app_access(app_dirname(c), W_OK) == 0\n                    && app_isdir(arg) <= 0\n                    && (app_access(arg, W_OK) == 0 || errno == ENOENT))) {\n                OPENSSL_free(c);\n                break;\n            }\n            OPENSSL_free(c);\n            if (errno == 0)\n                estr = "is a directory";\n            else\n                estr = strerror(errno);\n            errno = oerrno;\n#else\n            if (strcmp(arg, "-") == 0 || app_access(arg, W_OK) == 0\n                || errno == ENOENT)\n                break;\n            estr = strerror(errno);\n#endif\n            BIO_printf(bio_err,\n                       "%s: Cannot open output file %s, %s\\n",\n                       prog, arg, estr);\n            return -1;\n        case \'p\':\n        case \'n\':\n            if (!opt_int(arg, &ival)\n                    || (o->valtype == \'p\' && ival <= 0)) {\n                BIO_printf(bio_err,\n                           "%s: Non-positive number \\"%s\\" for -%s\\n",\n                           prog, arg, o->name);\n                return -1;\n            }\n            break;\n        case \'M\':\n            if (!opt_imax(arg, &imval)) {\n                BIO_printf(bio_err,\n                           "%s: Invalid number \\"%s\\" for -%s\\n",\n                           prog, arg, o->name);\n                return -1;\n            }\n            break;\n        case \'U\':\n            if (!opt_umax(arg, &umval)) {\n                BIO_printf(bio_err,\n                           "%s: Invalid number \\"%s\\" for -%s\\n",\n                           prog, arg, o->name);\n                return -1;\n            }\n            break;\n        case \'l\':\n            if (!opt_long(arg, &lval)) {\n                BIO_printf(bio_err,\n                           "%s: Invalid number \\"%s\\" for -%s\\n",\n                           prog, arg, o->name);\n                return -1;\n            }\n            break;\n        case \'u\':\n            if (!opt_ulong(arg, &ulval)) {\n                BIO_printf(bio_err,\n                           "%s: Invalid number \\"%s\\" for -%s\\n",\n                           prog, arg, o->name);\n                return -1;\n            }\n            break;\n        case \'c\':\n        case \'E\':\n        case \'F\':\n        case \'f\':\n            if (opt_format(arg,\n                           o->valtype == \'c\' ? OPT_FMT_PDS :\n                           o->valtype == \'E\' ? OPT_FMT_PDE :\n                           o->valtype == \'F\' ? OPT_FMT_PEMDER\n                           : OPT_FMT_ANY, &ival))\n                break;\n            BIO_printf(bio_err,\n                       "%s: Invalid format \\"%s\\" for -%s\\n",\n                       prog, arg, o->name);\n            return -1;\n        }\n        return o->retval;\n    }\n    if (unknown != NULL) {\n        dunno = p;\n        return unknown->retval;\n    }\n    BIO_printf(bio_err, "%s: Option unknown option -%s\\n", prog, p);\n    return -1;\n}', 'static int do_dir(const char *dirname, enum Hash h)\n{\n    BUCKET *bp, *nextbp;\n    HENTRY *ep, *nextep;\n    OPENSSL_DIR_CTX *d = NULL;\n    struct stat st;\n    unsigned char idmask[MAX_COLLISIONS / 8];\n    int n, numfiles, nextid, buflen, errs = 0;\n    size_t i;\n    const char *pathsep;\n    const char *filename;\n    char *buf, *copy;\n    STACK_OF(OPENSSL_STRING) *files = NULL;\n    if (app_access(dirname, W_OK) < 0) {\n        BIO_printf(bio_err, "Skipping %s, can\'t write\\n", dirname);\n        return 1;\n    }\n    buflen = strlen(dirname);\n    pathsep = (buflen && !ends_with_dirsep(dirname)) ? "/": "";\n    buflen += NAME_MAX + 1 + 1;\n    buf = app_malloc(buflen, "filename buffer");\n    if (verbose)\n        BIO_printf(bio_out, "Doing %s\\n", dirname);\n    if ((files = sk_OPENSSL_STRING_new_null()) == NULL) {\n        BIO_printf(bio_err, "Skipping %s, out of memory\\n", dirname);\n        exit(1);\n    }\n    while ((filename = OPENSSL_DIR_read(&d, dirname)) != NULL) {\n        if ((copy = strdup(filename)) == NULL\n                || sk_OPENSSL_STRING_push(files, copy) == 0) {\n            BIO_puts(bio_err, "out of memory\\n");\n            exit(1);\n        }\n    }\n    OPENSSL_DIR_end(&d);\n    sk_OPENSSL_STRING_sort(files);\n    numfiles = sk_OPENSSL_STRING_num(files);\n    for (n = 0; n < numfiles; ++n) {\n        filename = sk_OPENSSL_STRING_value(files, n);\n        if (BIO_snprintf(buf, buflen, "%s%s%s",\n                         dirname, pathsep, filename) >= buflen)\n            continue;\n        if (lstat(buf, &st) < 0)\n            continue;\n        if (S_ISLNK(st.st_mode) && handle_symlink(filename, buf) == 0)\n            continue;\n        errs += do_file(filename, buf, h);\n    }\n    sk_OPENSSL_STRING_pop_free(files, str_free);\n    for (i = 0; i < OSSL_NELEM(hash_table); i++) {\n        for (bp = hash_table[i]; bp; bp = nextbp) {\n            nextbp = bp->next;\n            nextid = 0;\n            memset(idmask, 0, (bp->num_needed + 7) / 8);\n            for (ep = bp->first_entry; ep; ep = ep->next)\n                if (ep->old_id < bp->num_needed)\n                    bit_set(idmask, ep->old_id);\n            for (ep = bp->first_entry; ep; ep = nextep) {\n                nextep = ep->next;\n                if (ep->old_id < bp->num_needed) {\n                    BIO_snprintf(buf, buflen, "%08x.%s%d", bp->hash,\n                                 suffixes[bp->type], ep->old_id);\n                    if (verbose)\n                        BIO_printf(bio_out, "link %s -> %s\\n",\n                                   ep->filename, buf);\n                } else if (ep->need_symlink) {\n                    while (bit_isset(idmask, nextid))\n                        nextid++;\n                    BIO_snprintf(buf, buflen, "%s%s%n%08x.%s%d",\n                                 dirname, pathsep, &n, bp->hash,\n                                 suffixes[bp->type], nextid);\n                    if (verbose)\n                        BIO_printf(bio_out, "link %s -> %s\\n",\n                                   ep->filename, &buf[n]);\n                    if (unlink(buf) < 0 && errno != ENOENT) {\n                        BIO_printf(bio_err,\n                                   "%s: Can\'t unlink %s, %s\\n",\n                                   opt_getprog(), buf, strerror(errno));\n                        errs++;\n                    }\n                    if (symlink(ep->filename, buf) < 0) {\n                        BIO_printf(bio_err,\n                                   "%s: Can\'t symlink %s, %s\\n",\n                                   opt_getprog(), ep->filename,\n                                   strerror(errno));\n                        errs++;\n                    }\n                    bit_set(idmask, nextid);\n                } else if (remove_links) {\n                    BIO_snprintf(buf, buflen, "%s%s%n%08x.%s%d",\n                                 dirname, pathsep, &n, bp->hash,\n                                 suffixes[bp->type], ep->old_id);\n                    if (verbose)\n                        BIO_printf(bio_out, "unlink %s\\n",\n                                   &buf[n]);\n                    if (unlink(buf) < 0 && errno != ENOENT) {\n                        BIO_printf(bio_err,\n                                   "%s: Can\'t unlink %s, %s\\n",\n                                   opt_getprog(), buf, strerror(errno));\n                        errs++;\n                    }\n                }\n                OPENSSL_free(ep->filename);\n                OPENSSL_free(ep);\n            }\n            OPENSSL_free(bp);\n        }\n        hash_table[i] = NULL;\n    }\n    OPENSSL_free(buf);\n    return errs;\n}', "static int ends_with_dirsep(const char *path)\n{\n    if (*path != '\\0')\n        path += strlen(path) - 1;\n# if defined __VMS\n    if (*path == ']' || *path == '>' || *path == ':')\n        return 1;\n# elif defined _WIN32\n    if (*path == '\\\\')\n        return 1;\n# endif\n    return *path == '/';\n}"]