]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3675] ntpq ccmds[] stores pointer to non-persistent storage
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 18 Jul 2020 06:33:48 +0000 (08:33 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 18 Jul 2020 06:33:48 +0000 (08:33 +0200)
[Bug 3676] compiler warnings (CMAC, interrupt_buf, typo, fallthrough)

bk: 5f1297cc-X63tZylegjWhq95Fu9t_Q

ChangeLog
ntpq/ntpq.c
sntp/libevent/evdns.c

index eeceaa9f10cb57b56caf561eaab50a81ec861f63..b256c3d36114d1788064ce56cf34eade6a5d3a81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+---
+* [Bug 3675] ntpq ccmds[] stores pointer to non-persistent storage
+* [Bug 3676] compiler warnings (CMAC, interrupt_buf, typo, fallthrough)
+  - applied patches by Gerry Garvey
+
 ---
 (4.2.8p15) 2020/06/23 Released by Harlan Stenn <stenn@ntp.org>
 
index 0382c0f948d7d3487b91725d179e6920ea942a8a..47b8ac08fb8fdbc437c8b4fba556f1cad1754e06 100644 (file)
@@ -397,8 +397,9 @@ u_int numassoc;             /* number of cached associations */
  * For commands typed on the command line (with the -c option)
  */
 size_t numcmds = 0;
-const char *ccmds[MAXCMDS];
-#define        ADDCMD(cp)      if (numcmds < MAXCMDS) ccmds[numcmds++] = (cp)
+size_t defcmds = 0;        /* Options on the command line are 'defined'! */
+char *ccmds[MAXCMDS];
+#define        ADDCMD(cp)      if (numcmds < MAXCMDS) ccmds[numcmds++] = estrdup(cp)
 
 /*
  * When multiple hosts are specified.
@@ -445,8 +446,11 @@ chost chosts[MAXHOSTS];
 # define SETJMP(x)     setjmp((x))
 # define LONGJMP(x, v) longjmp((x),(v))
 #endif
+
+#ifndef BUILD_AS_LIB
 static JMP_BUF         interrupt_buf;
 static volatile int    jump = 0;
+#endif
 
 /*
  * Points at file being currently printed into
@@ -613,7 +617,7 @@ ntpqmain(
                }
        }
 
-       if (numcmds == 0 && interactive == 0
+       if (defcmds == 0 && interactive == 0
            && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
                interactive = 1;
        }
@@ -624,10 +628,7 @@ ntpqmain(
                push_ctrl_c_handler(abortcmd);
 #endif /* SYS_WINNT */
 
-       if (numcmds == 0) {
-               (void) openhost(chosts[0].name, chosts[0].fam);
-               getcmds();
-       } else {
+       if (numcmds > 0) {
                for (ihost = 0; ihost < numhosts; ihost++) {
                        if (openhost(chosts[ihost].name, chosts[ihost].fam)) {
                                if (ihost && current_output)
@@ -639,6 +640,14 @@ ntpqmain(
                                }
                        }
                }
+               /* Release memory allocated in ADDCMD */
+               for (icmd = 0; icmd < numcmds; icmd++)
+                       free(ccmds[icmd]);
+       }
+
+       if (defcmds == 0) {        /* No command line commands, so go interactive */
+               (void) openhost(chosts[0].name, chosts[0].fam);
+               getcmds();
        }
 #ifdef SYS_WINNT
        WSACleanup();
@@ -845,10 +854,10 @@ dump_hex_printable(
 
                rowlen = (len > 16) ? 16 : (int)len;
                len -= rowlen;
-               
+
                do {
                        ch = *cdata++;
-                       
+
                        *xptr++ = s_xdig[ch >> 4  ];
                        *xptr++ = s_xdig[ch & 0x0F];
                        if (++xptr == lbuf + 3*8)
@@ -923,7 +932,7 @@ getresponse(
 
        memset(offsets, 0, sizeof(offsets));
        memset(counts , 0, sizeof(counts ));
-       
+
        /*
         * This is pretty tricky.  We may get between 1 and MAXFRAG packets
         * back in response to the request.  We peel the data out of
@@ -940,7 +949,7 @@ getresponse(
        seenlastfrag = 0;
 
        tobase = (uint32_t)time(NULL);
-       
+
        FD_ZERO(&fds);
 
        /*
@@ -988,7 +997,7 @@ getresponse(
                                 * execute RMW cycle on 'n'
                                 */
                }
-               
+
                if (n <= 0) {
                        /*
                         * Timed out.  Return what we have
@@ -1256,7 +1265,7 @@ getresponse(
                 */
                memcpy((char *)pktdata + offset, &rpkt.u, count);
                tobase = (uint32_t)time(NULL);
-               
+
                /*
                 * If we've seen the last fragment, look for holes in the sequence.
                 * If there aren't any, we're done.
@@ -2544,7 +2553,7 @@ showdrefid2str(void)
 
 
 /*
- * drefid - display/change "display hash" 
+ * drefid - display/change "display hash"
  */
 static void
 showdrefid(
@@ -3132,13 +3141,13 @@ static int/*BOOL*/ cp_uqchar(int ch)
 /* predicate: allowed chars inside a value name */
 static int/*BOOL*/ cp_namechar(int ch)
 {
-       return ch && (ch != ',' && ch != '=' && ch != '\r' && ch != '\n'); 
+       return ch && (ch != ',' && ch != '=' && ch != '\r' && ch != '\n');
 }
 
 /* predicate: characters *between* list items. We're relaxed here. */
 static int/*BOOL*/ cp_ivspace(int ch)
 {
-       return (ch == ',' || (ch > 0 && ch <= ' ')); 
+       return (ch == ',' || (ch > 0 && ch <= ' '));
 }
 
 /* get current character (or NUL when on end) */
@@ -3172,16 +3181,16 @@ str_strip(
        )
 {
        static const char empty[] = "";
-       
+
        if (*datap && len) {
                const char * cpl = *datap;
                const char * cpr = cpl + len;
-               
+
                while (cpl != cpr && *(const unsigned char*)cpl <= ' ')
                        ++cpl;
                while (cpl != cpr && *(const unsigned char*)(cpr - 1) <= ' ')
                        --cpr;
-               *datap = cpl;           
+               *datap = cpl;
                len = (size_t)(cpr - cpl);
        } else {
                *datap = empty;
@@ -3198,21 +3207,21 @@ pf_error(
        )
 {
 #   ifndef BUILD_AS_LIB
-       
+
        FILE *  ofp = (debug > 0) ? stdout : stderr;
        size_t  len = (size_t)(whend - where);
-       
+
        if (len > 50) /* *must* fit into an 'int'! */
                len = 50;
        fprintf(ofp, "nextvar: %s: '%.*s'\n",
                what, (int)len, where);
-       
+
 #   else  /*defined(BUILD_AS_LIB)*/
 
        UNUSED_ARG(what);
        UNUSED_ARG(where);
        UNUSED_ARG(whend);
-       
+
 #   endif /*defined(BUILD_AS_LIB)*/
 }
 
@@ -3228,7 +3237,7 @@ nextvar(
        )
 {
        enum PState     { sDone, sInit, sName, sValU, sValQ };
-       
+
        static char     name[MAXVARLEN], value[MAXVALLEN];
 
        const char      *cp, *cpend;
@@ -3236,13 +3245,13 @@ nextvar(
        size_t          nlen, vlen;
        int             ch;
        enum PState     st;
-       
+
        cpend = *datap + *datalen;
 
   again:
        np   = vp   = NULL;
        nlen = vlen = 0;
-       
+
        st = sInit;
        ch = pf_getch(datap, cpend);
 
@@ -3261,7 +3270,7 @@ nextvar(
                                goto final_done;
                        }
                        break;
-                           
+
                case sName:     /* collect name */
                        while (cp_namechar(ch))
                                ch = pf_nextch(datap, cpend);
@@ -3276,7 +3285,7 @@ nextvar(
                                st = sDone;
                        }
                        break;
-                       
+
                case sValU:     /* collect unquoted part(s) of value */
                        while (cp_uqchar(ch))
                                ch = pf_nextch(datap, cpend);
@@ -3290,7 +3299,7 @@ nextvar(
                                st = sDone;
                        }
                        break;
-                       
+
                case sValQ:     /* collect quoted part(s) of value */
                        while (cp_qschar(ch))
                                ch = pf_nextch(datap, cpend);
@@ -3302,7 +3311,7 @@ nextvar(
                                goto final_done;
                        }
                        break;
-                       
+
                default:
                        pf_error("state machine error, stop", *datap, cpend);
                        goto final_done;
@@ -3315,7 +3324,7 @@ nextvar(
         */
        nlen = str_strip(&np, nlen);
        vlen = str_strip(&vp, vlen);
-       
+
        if (nlen == 0) {
                goto again;
        }
@@ -3332,7 +3341,7 @@ nextvar(
        memcpy(name, np, nlen);
        name[nlen] = '\0';
        *vname = name;
-       
+
        memcpy(value, vp, vlen);
        value[vlen] = '\0';
        *vvalue = value;
@@ -3541,7 +3550,7 @@ tstflags(
        )
 {
 #      if CBLEN < 10
-#       error BLEN is too small -- increase!
+#       error CBLEN is too small -- increase!
 #      endif
 
        char *cp, *s;
@@ -3566,7 +3575,7 @@ tstflags(
                cb -= l;
        } else {
                const char *sep;
-               
+
                sep = " ";
                for (i = 0; i < COUNTOF(tstflagnames); i++) {
                        if (val & 0x1) {
@@ -3664,8 +3673,8 @@ cookedprint(
                        } else if (decodenetnum(value, &hval)) {
                                if (datatype == TYPE_CLOCK && IS_IPV4(&hval)) {
                                        /*
-                                        * Workaround to override numeric refid formats 
-                                        * for refclocks received from faulty nptd servers 
+                                        * Workaround to override numeric refid formats
+                                        * for refclocks received from faulty nptd servers
                                         * and output them as text.
                                         */
                                        int i;
@@ -3682,7 +3691,7 @@ cookedprint(
                                                output(fp, name, stoa(&hval));
                                        } else {
                                                char refid_buf[12];
-                                               snprintf (refid_buf, sizeof(refid_buf), 
+                                               snprintf (refid_buf, sizeof(refid_buf),
                                                          "0x%08x", ntohl(addr2refid(&hval)));
                                                output(fp, name, refid_buf);
                                        }
@@ -3819,7 +3828,7 @@ grow_assoc_cache(void)
        if (0 == prior_sz) {
                new_sz -= 4 * sizeof(void *);
        }
-       assoc_cache = erealloc_zero(assoc_cache, new_sz, prior_sz); 
+       assoc_cache = erealloc_zero(assoc_cache, new_sz, prior_sz);
        prior_sz = new_sz;
        assoc_cache_slots = (u_int)(new_sz / sizeof(assoc_cache[0]));
 }
@@ -3848,10 +3857,14 @@ ntpq_custom_opt_handler(
                exit(1);
 
        case 'c':
+               if ((pOptDesc->fOptState & OPTST_SET_MASK) == OPTST_DEFINED)
+                       defcmds++;
                ADDCMD(pOptDesc->pzLastArg);
                break;
 
        case 'p':
+               if ((pOptDesc->fOptState & OPTST_SET_MASK) == OPTST_DEFINED)
+                       defcmds++;
                ADDCMD("peers");
                break;
        }
@@ -3887,7 +3900,7 @@ list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg)
        const char    *name, **seen;
        struct hstate *hstate = arg;
        const char    *cp;
-       
+
        /* m is MD obj, from is name or alias, to is base name for alias */
        if (!m || !from || to)
                return; /* Ignore aliases */
@@ -3896,19 +3909,19 @@ list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg)
        /* Keep this consistent with keytype_from_text() in ssl_init.c. */
        if (EVP_MD_size(m) > (MAX_MAC_LEN - sizeof(keyid_t)))
                return;
-       
+
        name = EVP_MD_name(m);
-       
+
        /* Lowercase names aren't accepted by keytype_from_text in ssl_init.c */
-       
+
        for (cp = name; *cp; cp++)
                if (islower((unsigned char)*cp))
                        return;
 
        len = (cp - name) + 1;
-       
+
        /* There are duplicates.  Discard if name has been seen. */
-       
+
        for (seen = hstate->seen; *seen; seen++)
                if (!strcmp(*seen, name))
                        return;
@@ -3917,7 +3930,7 @@ list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg)
        hstate->seen = erealloc(hstate->seen, n * sizeof(*seen));
        hstate->seen[n-2] = name;
        hstate->seen[n-1] = NULL;
-       
+
        if (hstate->list != NULL)
                len += strlen(hstate->list);
 
@@ -3931,11 +3944,11 @@ list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg)
        } else {
                hstate->list = (char *)erealloc(hstate->list, len);
        }
-       
+
        sprintf(hstate->list + strlen(hstate->list), "%s%s",
                ((hstate->idx >= K_PER_LINE) ? K_NL_PFX_STR : K_DELIM_STR),
                name);
-       
+
        if (hstate->idx >= K_PER_LINE)
                hstate->idx = 1;
        else
@@ -3955,7 +3968,7 @@ insert_cmac(char *list)
 
        /* If list empty, we need to insert CMAC on new line */
        insert = (!list || !*list);
-       
+
        if (insert) {
                len = strlen(K_NL_PFX_STR) + strlen(CMAC);
                list = (char *)erealloc(list, len + 1);
@@ -3964,41 +3977,41 @@ insert_cmac(char *list)
                /* Check if CMAC already in list - future proofing */
                const char *cmac_sn;
                char *cmac_p;
-               
+
                cmac_sn = OBJ_nid2sn(NID_cmac);
                cmac_p = list;
                insert = cmac_sn != NULL && *cmac_sn != '\0';
-               
+
                /* CMAC in list if found, followed by nul char or ',' */
                while (insert && NULL != (cmac_p = strstr(cmac_p, cmac_sn))) {
                        cmac_p += strlen(cmac_sn);
                        /* Still need to insert if not nul and not ',' */
                        insert = *cmac_p && ',' != *cmac_p;
                }
-               
+
                /* Find proper insertion point */
                if (insert) {
                        char *last_nl;
                        char *point;
                        char *delim;
                        int found;
-                       
+
                        /* Default to start if list empty */
                        found = 0;
                        delim = list;
                        len = strlen(list);
-                       
+
                        /* While new lines */
                        while (delim < list + len && *delim &&
                               !strncmp(K_NL_PFX_STR, delim, strlen(K_NL_PFX_STR))) {
                                point = delim + strlen(K_NL_PFX_STR);
-                               
+
                                /* While digest names on line */
                                while (point < list + len && *point) {
                                        /* Another digest after on same or next line? */
                                        delim = strstr( point, K_DELIM_STR);
                                        last_nl = strstr( point, K_NL_PFX_STR);
-                                       
+
                                        /* No - end of list */
                                        if (!delim && !last_nl) {
                                                delim = list + len;
@@ -4007,13 +4020,13 @@ insert_cmac(char *list)
                                                if (last_nl && (!delim || last_nl < delim)) {
                                                        delim = last_nl;
                                                }
-                                       
+
                                        /* Found insertion point where CMAC before entry? */
                                        if (strncmp(CMAC, point, delim - point) < 0) {
                                                found = 1;
                                                break;
                                        }
-                                       
+
                                        if (delim < list + len && *delim &&
                                            !strncmp(K_DELIM_STR, delim, strlen(K_DELIM_STR))) {
                                                point += strlen(K_DELIM_STR);
@@ -4022,7 +4035,7 @@ insert_cmac(char *list)
                                        }
                                } /* While digest names on line */
                        } /* While new lines */
-                       
+
                        /* If found in list */
                        if (found) {
                                /* insert cmac and delim */
@@ -4034,8 +4047,8 @@ insert_cmac(char *list)
                                /* move to handle src/dest overlap */
                                memmove(point + strlen(CMAC) + strlen(K_DELIM_STR),
                                        point, strlen(point) + 1);
-                               strncpy(point, CMAC, strlen(CMAC));
-                               strncpy(point + strlen(CMAC), K_DELIM_STR, strlen(K_DELIM_STR));
+                               memcpy(point, CMAC, strlen(CMAC));
+                               memcpy(point + strlen(CMAC), K_DELIM_STR, strlen(K_DELIM_STR));
                        } else {        /* End of list */
                                /* append delim and cmac */
                                len += strlen(K_DELIM_STR) + strlen(CMAC);
@@ -4058,21 +4071,21 @@ static char *
 list_digest_names(void)
 {
        char *list = NULL;
-       
+
 #ifdef OPENSSL
 # ifdef HAVE_EVP_MD_DO_ALL_SORTED
        struct hstate hstate = { NULL, NULL, K_PER_LINE+1 };
-       
+
        /* replace calloc(1, sizeof(const char *)) */
        hstate.seen = (const char **)emalloc_zero(sizeof(const char *));
-       
+
        INIT_SSL();
        EVP_MD_do_all_sorted(list_md_fn, &hstate);
        list = hstate.list;
        free(hstate.seen);
-       
+
        list = insert_cmac(list);       /* Insert CMAC into SSL digests list */
-       
+
 # else
        list = (char *)emalloc(sizeof("md5, others (upgrade to OpenSSL-1.0 for full list)"));
        strcpy(list, "md5, others (upgrade to OpenSSL-1.0 for full list)");
@@ -4081,7 +4094,7 @@ list_digest_names(void)
        list = (char *)emalloc(sizeof("md5"));
        strcpy(list, "md5");
 #endif
-       
+
        return list;
 }
 #endif /* !defined(BUILD_AS_LIB) */
@@ -4103,7 +4116,7 @@ push_ctrl_c_handler(
                ctrlc_stack_len = size + 1;
                return TRUE;
        }
-       return FALSE;   
+       return FALSE;
 }
 
 int/*BOOL*/
index 60f4db5c5fba1b0fc1b0e5849f1d473ae1c4dc50..52a2b6bce60415ea30aa1076a9d7327f88c8f71a 100644 (file)
@@ -2271,6 +2271,7 @@ evdns_request_transmit(struct request *req) {
                retcode = 1;
                /* fall through: we'll set a timeout, which will time out,
                 * and make us retransmit the request anyway. */
+               /* FALLTHROUGH */
        default:
                /* all ok */
                log(EVDNS_LOG_DEBUG,