From: Dave Hart Date: Fri, 2 Jul 2010 06:43:21 +0000 (+0100) Subject: [Bug 1581] size_t printf format string mismatches, IRIG string buffers X-Git-Tag: NTP_4_2_6P2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89100e52d51ea57b9b39f9cc8f74485c42cb246c;p=thirdparty%2Fntp.git [Bug 1581] size_t printf format string mismatches, IRIG string buffers 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 --- diff --git a/ChangeLog b/ChangeLog index 8f99954c5..9482686e1 100644 --- 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 * [Bug 1570] serial clock drivers get outdated input from kernel tty diff --git a/libntp/ssl_init.c b/libntp/ssl_init.c index f15de341e..1873ea43d 100644 --- a/libntp/ssl_init.c +++ b/libntp/ssl_init.c @@ -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 diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 72e9e53e2..69912b07b 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -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); } diff --git a/ntpd/ntp_intres.c b/ntpd/ntp_intres.c index a3c66117d..24af82167 100644 --- a/ntpd/ntp_intres.c +++ b/ntpd/ntp_intres.c @@ -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; diff --git a/ntpd/ntp_request.c b/ntpd/ntp_request.c index 95cb1e5c2..f07456226 100644 --- a/ntpd/ntp_request.c +++ b/ntpd/ntp_request.c @@ -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; } diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index 009b798d1..896bf1039 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -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 diff --git a/ntpd/refclock_acts.c b/ntpd/refclock_acts.c index 71923ce51..be69ce6cd 100644 --- a/ntpd/refclock_acts.c +++ b/ntpd/refclock_acts.c @@ -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 diff --git a/ntpd/refclock_irig.c b/ntpd/refclock_irig.c index 8ff17ccf9..0a4747319 100644 --- a/ntpd/refclock_irig.c +++ b/ntpd/refclock_irig.c @@ -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; /* diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index bee764086..21a8f7838 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -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; } diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 6369753ef..382b25cba 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -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; }