]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1874] ntpq -c "rv 0 sys_var_list" empty.
authorDave Hart <hart@ntp.org>
Sat, 2 Apr 2011 06:32:52 +0000 (06:32 +0000)
committerDave Hart <hart@ntp.org>
Sat, 2 Apr 2011 06:32:52 +0000 (06:32 +0000)
bk: 4d96c314kG03GLiVP47v8luEVJM4hg

ChangeLog
ntpd/ntp_control.c
ntpq/ntpq.c

index 420245c1f76737982bb5ad32fee33ebdba84b77e..3f4ca2dc53733d231ebd6a999d2513d0b78dc713 100644 (file)
--- 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 <stenn@ntp.org>
 * [Bug 1732] ntpd ties up CPU on disconnected USB refclock.
 * [Bug 1861] tickadj build failure using uClibc.
index e247238c40a24b0c8299541668323c2a8787b8b6..82cbc8008f4ec1a2db61c91f36ae15c90ae44019 100644 (file)
@@ -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;
index a6f9b4fc24f71c24b68e2643fb140b9fd1ba7e30..9bace34bb94fe3083f70e3a18d12f80282f74cf4 100644 (file)
@@ -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;