]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1581] size_t printf format string mismatches, IRIG string buffers
authorDave Hart <hart@ntp.org>
Fri, 2 Jul 2010 06:43:21 +0000 (07:43 +0100)
committerDave Hart <hart@ntp.org>
Fri, 2 Jul 2010 06:43:21 +0000 (07:43 +0100)
  undersized.  Mostly backported from earlier ntp-dev fixes by Jürgen
  Perlinger, The exceptions are ntp_intres.c and refclock_irig.c.

bk: 4c2d8a895pq47Cdds3NrAoBiS-6ekw

ChangeLog
libntp/ssl_init.c
ntpd/ntp_config.c
ntpd/ntp_intres.c
ntpd/ntp_request.c
ntpd/ntp_scanner.c
ntpd/refclock_acts.c
ntpd/refclock_irig.c
ntpdc/ntpdc.c
ntpq/ntpq.c

index 8f99954c54cb8caeba38c5ae890601bf0a88581b..9482686e1e0b3b312538baf36fbe5307173352e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
 ---
+
+* [Bug 1581] size_t printf format string mismatches, IRIG string buffers
+  undersized.  Mostly backported from earlier ntp-dev fixes by Jürgen
+  Perlinger.
+
+---
 (4.2.6p2-RC7) 2010/06/19 Released by Harlan Stenn <stenn@ntp.org>
 
 * [Bug 1570] serial clock drivers get outdated input from kernel tty
index f15de341e16f4fd627164c5c8796e0bad4fd1b46..1873ea43dda9ed3f2963f1e713dadcd079a3aa81 100644 (file)
@@ -61,6 +61,7 @@ keytype_from_text(
        size_t *pdigest_len
        )
 {
+       const u_long    max_digest_len = MAX_MAC_LEN - sizeof(keyid_t);
        int             key_type;
        u_int           digest_len;
 #ifdef OPENSSL
@@ -97,13 +98,13 @@ keytype_from_text(
                EVP_DigestFinal(&ctx, digest, &digest_len);
                if (digest_len + sizeof(keyid_t) > MAX_MAC_LEN) {
                        fprintf(stderr,
-                               "key type %s %u octet digests are too big, max %u\n",
+                               "key type %s %u octet digests are too big, max %lu\n",
                                keytype_name(key_type), digest_len,
-                               MAX_MAC_LEN - sizeof(keyid_t));
+                               max_digest_len);
                        msyslog(LOG_ERR,
-                               "key type %s %u octet digests are too big, max %u",
+                               "key type %s %u octet digests are too big, max %lu\n",
                                keytype_name(key_type), digest_len,
-                               MAX_MAC_LEN - sizeof(keyid_t));
+                               max_digest_len);
                        return 0;
                }
 #else
index 72e9e53e28a17d68e016cd0d7c2f0448a1e86cc9..69912b07bd1acf5e970d7325d419ca4b1ae50dda 100644 (file)
@@ -2724,8 +2724,8 @@ config_phone(
                        sys_phone[i++] = estrdup(*s);
                else
                        msyslog(LOG_INFO,
-                               "phone: Number of phone entries exceeds %d. Ignoring phone %s...",
-                               COUNTOF(sys_phone) - 1, *s);
+                               "phone: Number of phone entries exceeds %lu. Ignoring phone %s...",
+                               (u_long)(COUNTOF(sys_phone) - 1), *s);
                s = next_node(s);
        }
 
@@ -2882,8 +2882,8 @@ config_ttl(
                        sys_ttl[i++] = (u_char)*curr_ttl;
                else
                        msyslog(LOG_INFO,
-                               "ttl: Number of TTL entries exceeds %d. Ignoring TTL %d...",
-                               COUNTOF(sys_ttl), *curr_ttl);
+                               "ttl: Number of TTL entries exceeds %lu. Ignoring TTL %d...",
+                               (u_long)COUNTOF(sys_ttl), *curr_ttl);
 
                curr_ttl = next_node(curr_ttl);
        }
index a3c66117ddc9577ca21359cf6248d82d614a5d06..24af82167209becdb5fde6d18598960c41d103ad 100644 (file)
@@ -829,9 +829,10 @@ request(
                total_len = pchEnd - (char *)&reqpkt;
                if (total_len > sizeof(reqpkt)) {
                        msyslog(LOG_ERR,
-                               "intres total_len %u limit is %u (%u octet digest)\n",
-                               total_len, sizeof(reqpkt),
-                               req_hashlen);
+                               "intres total_len %lu limit is %lu (%lu octet digest)\n",
+                               (u_long)total_len,
+                               (u_long)sizeof(reqpkt),
+                               (u_long)req_hashlen);
                        resolver_exit(1);
                }
        } else {
@@ -849,7 +850,8 @@ request(
                if ((size_t)n != req_hashlen + sizeof(reqpkt.keyid)) {
                        msyslog(LOG_ERR,
                                "intres maclen %d expected %u\n",
-                               n, req_hashlen + sizeof(reqpkt.keyid));
+                               n, (u_long)(req_hashlen +
+                               sizeof(reqpkt.keyid)));
                        resolver_exit(1);
                }
                req_len += n;
index 95cb1e5c2b69ca13e3906ece22ccaf4f5dec73a7..f07456226f6ccef8e91d936a0174d2d97276bdc1 100644 (file)
@@ -582,25 +582,26 @@ process_private(
                 */
                if (!INFO_IS_AUTH(inpkt->auth_seq) || !info_auth_keyid
                    || ntohl(tailinpkt->keyid) != info_auth_keyid) {
-                       DPRINTF(5, ("failed auth %d info_auth_keyid %u pkt keyid %u maclen %u\n",
+                       DPRINTF(5, ("failed auth %d info_auth_keyid %u pkt keyid %u maclen %lu\n",
                                    INFO_IS_AUTH(inpkt->auth_seq),
                                    info_auth_keyid,
-                                   ntohl(tailinpkt->keyid), mac_len));
+                                   ntohl(tailinpkt->keyid), (u_long)mac_len));
 #ifdef DEBUG
                        msyslog(LOG_DEBUG,
-                               "process_private: failed auth %d info_auth_keyid %u pkt keyid %u maclen %u\n",
+                               "process_private: failed auth %d info_auth_keyid %u pkt keyid %u maclen %lu\n",
                                INFO_IS_AUTH(inpkt->auth_seq),
                                info_auth_keyid,
-                               ntohl(tailinpkt->keyid), mac_len);
+                               ntohl(tailinpkt->keyid), (u_long)mac_len);
 #endif
                        req_ack(srcadr, inter, inpkt, INFO_ERR_AUTH);
                        return;
                }
                if (recv_len > REQ_LEN_NOMAC + MAX_MAC_LEN) {
-                       DPRINTF(5, ("bad pkt length %d\n", recv_len));
+                       DPRINTF(5, ("bad pkt length %lu\n", 
+                                   (u_long)recv_len));
                        msyslog(LOG_ERR,
-                               "process_private: bad pkt length %d",
-                               recv_len);
+                               "process_private: bad pkt length %lu",
+                               (u_long)recv_len);
                        req_ack(srcadr, inter, inpkt, INFO_ERR_FMT);
                        return;
                }
index 009b798d10a594fe9b2d88f4ca0633f3908cee0c..896bf103929be195252d38983694c707c2fd77bf 100644 (file)
@@ -636,8 +636,8 @@ normal_return:
 lex_too_long:
        yytext[min(sizeof(yytext) - 1, 50)] = 0;
        msyslog(LOG_ERR, 
-               "configuration item on line %d longer than limit of %d, began with '%s'",
-               ip_file->line_no, sizeof(yytext) - 1, yytext);
+               "configuration item on line %d longer than limit of %lu, began with '%s'",
+               ip_file->line_no, (u_long)(sizeof(yytext) - 1), yytext);
 
        /*
         * If we hit the length limit reading the startup configuration
index 71923ce514ec558706e23fc07d2ec0886ec81b94..be69ce6cd58126ce6a7b1598bccb7c8b165209cf 100644 (file)
@@ -362,9 +362,9 @@ acts_message(
        up = (struct actsunit *)pp->unitptr;
 #ifdef DEBUG
        ioctl(pp->io.fd, TIOCMGET, (char *)&modem);
-       snprintf(tbuf, sizeof(tbuf), "acts: %04x (%d %d) %d %s", modem,
-           up->state, up->timer, strlen(pp->a_lastcode),
-           pp->a_lastcode);
+       snprintf(tbuf, sizeof(tbuf), "acts: %04x (%d %d) %lu %s", modem,
+                up->state, up->timer, (u_long)strlen(pp->a_lastcode),
+                pp->a_lastcode);
        if (debug)
                printf("%s\n", tbuf);
 #endif
index 8ff17ccf946a1a6879190067f399305ee8041f4d..0a4747319c4b8444244aadea9dfb692a7b8a8bf8 100644 (file)
@@ -844,11 +844,11 @@ irig_decode(
         * Local variables
         */
        int     syncdig;        /* sync digit (Spectracom) */
-       char    sbs[6];         /* binary seconds since 0h */
-       char    spare[2];       /* mulligan digits */
+       char    sbs[6 + 1];     /* binary seconds since 0h */
+       char    spare[2 + 1];   /* mulligan digits */
        int     temp;
 
-        pp = peer->procptr;
+       pp = peer->procptr;
        up = (struct irigunit *)pp->unitptr;
 
        /*
index bee7640863dbd67d4122dd01fc255bc0bde4a35a..21a8f783857117adc207c525c9e30056a6ae0260 100644 (file)
@@ -796,8 +796,8 @@ getresponse(
        if ((size_t)datasize > (n-RESP_HEADER_SIZE)) {
                if (debug)
                    printf(
-                           "Received items %d, size %d (total %d), data in packet is %d\n",
-                           items, size, datasize, n-RESP_HEADER_SIZE);
+                           "Received items %d, size %d (total %d), data in packet is %lu\n",
+                           items, size, datasize, (u_long)(n-RESP_HEADER_SIZE));
                goto again;
        }
 
@@ -981,9 +981,9 @@ sendrequest(
                return 1;
        } else if (maclen != (info_auth_hashlen + sizeof(keyid_t))) {
                fprintf(stderr,
-                       "%d octet MAC, %u expected with %u octet digest\n",
-                       maclen, (info_auth_hashlen + sizeof(keyid_t)),
-                       info_auth_hashlen);
+                       "%d octet MAC, %lu expected with %lu octet digest\n",
+                       maclen, (u_long)(info_auth_hashlen + sizeof(keyid_t)),
+                       (u_long)info_auth_hashlen);
                return 1;
        }
        return sendpkt(&qpkt, reqsize + maclen);
@@ -1793,9 +1793,9 @@ keytype(
        int             key_type;
 
        if (!pcmd->nargs) {
-               fprintf(fp, "keytype is %s with %u octet digests\n",
+               fprintf(fp, "keytype is %s with %lu octet digests\n",
                        keytype_name(info_auth_keytype),
-                       info_auth_hashlen);
+                       (u_long)info_auth_hashlen);
                return;
        }
 
index 6369753ef1267a866d16f194c1c851bfa1d148d0..382b25cba47aecfd4e0e58e81f24efb98b931bf3 100644 (file)
@@ -786,7 +786,7 @@ sendpkt(
        )
 {
        if (debug >= 3)
-               printf("Sending %u octets\n", xdatalen);
+               printf("Sending %lu octets\n", (u_long)xdatalen);
 
        if (send(sockfd, xdata, (size_t)xdatalen, 0) == -1) {
                warning("write to %s failed", currenthost, "");
@@ -1299,9 +1299,9 @@ sendrequest(
                return 1;
        } else if ((size_t)maclen != (info_auth_hashlen + sizeof(keyid_t))) {
                fprintf(stderr,
-                       "%d octet MAC, %u expected with %u octet digest\n",
-                       maclen, (info_auth_hashlen + sizeof(keyid_t)),
-                       info_auth_hashlen);
+                       "%d octet MAC, %lu expected with %lu octet digest\n",
+                       maclen, (u_long)(info_auth_hashlen + sizeof(keyid_t)),
+                       (u_long)info_auth_hashlen);
                return 1;
        }
        
@@ -2380,9 +2380,9 @@ keytype(
        int             key_type;
 
        if (!pcmd->nargs) {
-               fprintf(fp, "keytype is %s with %u octet digests\n",
+               fprintf(fp, "keytype is %s with %lu octet digests\n",
                        keytype_name(info_auth_keytype),
-                       info_auth_hashlen);
+                       (u_long)info_auth_hashlen);
                return;
        }