From: Dave Hart Date: Sat, 2 Apr 2011 06:32:52 +0000 (+0000) Subject: [Bug 1874] ntpq -c "rv 0 sys_var_list" empty. X-Git-Tag: NTP_4_2_7P144~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0f39529be2a38d50f6ccece00556bbcfd73d726;p=thirdparty%2Fntp.git [Bug 1874] ntpq -c "rv 0 sys_var_list" empty. bk: 4d96c314kG03GLiVP47v8luEVJM4hg --- diff --git a/ChangeLog b/ChangeLog index 420245c1f..3f4ca2dc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1874] ntpq -c "rv 0 sys_var_list" empty. (4.2.7p143) 2011/03/31 Released by Harlan Stenn * [Bug 1732] ntpd ties up CPU on disconnected USB refclock. * [Bug 1861] tickadj build failure using uClibc. diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index e247238c4..82cbc8008 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -307,7 +307,7 @@ static const struct ctl_proc control_codes[] = { #define CC_FUDGEVAL2 10 #define CC_FLAGS 11 #define CC_DEVICE 12 -#define CC_VARLIST 13 +#define CC_VARLIST 13 #define CC_MAXCODE CC_VARLIST /* @@ -1648,17 +1648,15 @@ ctl_putsys( { l_fp tmp; char str[256]; - char buf[CTL_MAX_DATA_LEN]; u_int u; double kb; double dtemp; - char *s, *t, *be; const char *ss; - int i; + size_t len; + int firstvarname; const struct ctl_var *k; #ifdef AUTOKEY struct cert_info *cp; - char cbuf[256]; #endif /* AUTOKEY */ #ifdef KERNEL_PLL static struct timex ntx; @@ -1800,54 +1798,39 @@ ctl_putsys( break; case CS_VARLIST: - s = buf; - be = buf + sizeof(buf); - if (strlen(sys_var[CS_VARLIST].text) + 4 > sizeof(buf)) - break; /* really long var name */ - - snprintf(s, sizeof(buf), "%s=\"", + snprintf(str, sizeof(str), "%s=\"", sys_var[CS_VARLIST].text); - s += strlen(s); - t = s; + ctl_putdata(str, strlen(str), TRUE); + + firstvarname = TRUE; for (k = sys_var; !(EOV & k->flags); k++) { if (PADDING & k->flags) continue; - i = strlen(k->text); - if (s + i + 1 >= be) - break; - - if (s != t) - *s++ = ','; - memcpy(s, k->text, i); - s += i; + len = strlen(k->text); + if (0 == len) + continue; + if (!firstvarname) + ctl_putdata(",", 1, TRUE); + else + firstvarname = FALSE; + ctl_putdata(k->text, len, TRUE); } for (k = ext_sys_var; k && !(EOV & k->flags); k++) { if (PADDING & k->flags) continue; - - ss = k->text; - if (NULL == ss) + if (NULL == k->text) continue; - - while (*ss != '\0' && *ss != '=') - ss++; - i = ss - k->text; - if (s + i + 1 >= be) - break; - - if (s != t) - *s++ = ','; - memcpy(s, k->text, (unsigned)i); - s += i; + ss = strchr(k->text, '='); + if (NULL == ss) + len = strlen(k->text); + else + len = ss - k->text; + ctl_putdata(",", 1, TRUE); + ctl_putdata(k->text, len, TRUE); } - if (s + 2 >= be) - break; - *s++ = '"'; - *s = '\0'; - - ctl_putdata(buf, (unsigned)(s - buf), 0); + ctl_putdata("\"", 1, TRUE); break; case CS_TAI: @@ -2243,10 +2226,10 @@ ctl_putsys( case CS_CERTIF: for (cp = cinfo; cp != NULL; cp = cp->link) { - snprintf(cbuf, sizeof(cbuf), "%s %s 0x%x", + snprintf(str, sizeof(str), "%s %s 0x%x", cp->subject, cp->issuer, cp->flags); - ctl_putstr(sys_var[CS_CERTIF].text, cbuf, - strlen(cbuf)); + ctl_putstr(sys_var[CS_CERTIF].text, str, + strlen(str)); ctl_putfs(sys_var[CS_REVTIME].text, cp->last); } break; diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index a6f9b4fc2..9bace34bb 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -303,7 +303,7 @@ struct xcmd builtins[] = { #define MAXLINE 512 /* maximum line length */ #define MAXTOKENS (1+MAXARGS+2) /* maximum number of usable tokens */ #define MAXVARLEN 256 /* maximum length of a variable name */ -#define MAXVALLEN 400 /* maximum length of a variable value */ +#define MAXVALLEN 2048 /* maximum length of a variable value */ #define MAXOUTLINE 72 /* maximum length of an output line */ #define SCREENWIDTH 76 /* nominal screen width in columns */ @@ -2585,10 +2585,10 @@ atoascii( size_t out_octets ) { - register const u_char * pchIn; - const u_char * pchInLimit; - register u_char * pchOut; - register u_char c; + const u_char * pchIn; + const u_char * pchInLimit; + u_char * pchOut; + u_char c; pchIn = (const u_char *)in; pchInLimit = pchIn + in_octets; @@ -2761,7 +2761,7 @@ nextvar( if ('"' == *np) { do { np++; - } while (np < cpend && '"' != *np && '\r' != *np); + } while (np < cpend && '"' != *np); if (np < cpend && '"' == *np) np++; } else { @@ -2769,8 +2769,8 @@ nextvar( np++; } len = np - cp; - if (np >= cpend || len >= sizeof(value) || - (',' != *np && '\r' != *np)) + if (np > cpend || len >= sizeof(value) || + (np < cpend && ',' != *np && '\r' != *np)) return 0; memcpy(value, cp, len); /* @@ -3049,7 +3049,7 @@ cookedprint( l_fp lfparr[8]; char b[12]; char bn[2 * MAXVARLEN]; - char bv[2 * MAXVARLEN]; + char bv[2 * MAXVALLEN]; UNUSED_ARG(datatype); @@ -3146,7 +3146,7 @@ cookedprint( if (output_raw != 0) { atoascii(name, MAXVARLEN, bn, sizeof(bn)); - atoascii(value, MAXVARLEN, bv, sizeof(bv)); + atoascii(value, MAXVALLEN, bv, sizeof(bv)); if (output_raw != '*') { len = strlen(bv); bv[len] = output_raw;