[Git][NTPsec/ntpsec][master] Repair rv 0 sys_var_list
Hal Murray (@hal.murray)
gitlab at mg.gitlab.com
Mon Jul 22 04:49:15 UTC 2024
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
879beeb2 by Hal Murray at 2024-07-21T19:41:01-07:00
Repair rv 0 sys_var_list
- - - - -
1 changed file:
- ntpd/ntp_control.c
Changes:
=====================================
ntpd/ntp_control.c
=====================================
@@ -115,6 +115,8 @@ static void ctl_putclock (int, struct refclockstat *, bool);
static const struct var * ctl_getitem(const struct var *, char **);
static void ctl_putsys (const struct var *);
static void ctl_putspecial (const struct var *);
+void do_sys_var_list(const char* name, const struct var* v);
+
static const struct ctl_var *ctl_getitem2(const struct ctl_var *, char **);
static unsigned short ctlsysstatus (void);
@@ -1525,7 +1527,6 @@ ctl_putspecial(const struct var * v) {
l_fp tmp;
uint64_t u;
l_fp now;
- struct ctl_var *cv;
switch (v->p.special) {
case vs_peer:
@@ -1561,9 +1562,7 @@ ctl_putspecial(const struct var * v) {
ctl_putuint(v->name, mon_get_oldest_age(now));
break;
case vs_varlist:
- for (cv = ext_sys_var; !(EOV & cv->flags); cv++) {
- ctl_putdata(cv->text, strlen(cv->text), false);
- }
+ do_sys_var_list(v->name, sys_var);
break;
default:
/* -Wswitch-enum will warn if this is possible */
@@ -1774,6 +1773,47 @@ ctl_putpeer(
#undef CV_NAME
+bool CF_VARLIST(
+ const struct ctl_var *entry,
+ const struct ctl_var *table1,
+ const struct ctl_var *table2
+ ) {
+ char buf[1500]; // Arbitrary length greeter than used to be.
+ char *buffer_lap, *buffer_end;
+ bool first = true;
+ ssize_t increment;
+ memset(buf, '.', sizeof(buf));
+ buf[0] = '\0';
+ buffer_lap = buf;
+ buffer_end = buf + sizeof(buf);
+ if (strlen(entry->text) + 4 > sizeof(buf)) {
+ return false; // really long var name
+ }
+
+ snprintf(buffer_lap, sizeof(buf), "%s=\"", entry->text);
+ buffer_lap += strlen(buffer_lap);
+ increment = CI_VARLIST(buffer_lap, buffer_end,
+ table1, &first);
+ if (increment <= 0) {
+ return false;
+ }
+ buffer_lap += increment;
+ increment = CI_VARLIST(buffer_lap, buffer_end,
+ table2, &first);
+ if (increment < 0) {
+ return false;
+ }
+ buffer_lap += increment;
+ if (buffer_lap + 2 >= buffer_end)
+ return false;
+
+ *buffer_lap++ = '"';
+ *buffer_lap = '\0';
+ ctl_putdata(buf, (unsigned)(buffer_lap - buf), false);
+ return true;
+}
+
+
ssize_t CI_VARLIST(
char *buffer_lap,
char *buf_end,
@@ -1812,44 +1852,42 @@ ssize_t CI_VARLIST(
}
-bool CF_VARLIST(
- const struct ctl_var *entry,
- const struct ctl_var *table1,
- const struct ctl_var *table2
- ) {
- char buf[1500]; // Arbitrary length greeter than used to be.
- char *buffer_lap, *buffer_end;
+void do_sys_var_list(const char* name, const struct var* v) {
+ /* This has to be big enough for the whole answer -- all names.
+ * On 2024-Jul-21, that was almost 3000 characters.
+ * We could split this into two: counters and other. */
+ char buf[5000];
+ char *buffer;
bool first = true;
- ssize_t increment;
+ int length;
+
memset(buf, '.', sizeof(buf));
buf[0] = '\0';
- buffer_lap = buf;
- buffer_end = buf + sizeof(buf);
- if (strlen(entry->text) + 4 > sizeof(buf)) {
- return false; // really long var name
- }
-
- snprintf(buffer_lap, sizeof(buf), "%s=\"", entry->text);
- buffer_lap += strlen(buffer_lap);
- increment = CI_VARLIST(buffer_lap, buffer_end,
- table1, &first);
- if (increment <= 0) {
- return false;
- }
- buffer_lap += increment;
- increment = CI_VARLIST(buffer_lap, buffer_end,
- table2, &first);
- if (increment < 0) {
- return false;
- }
- buffer_lap += increment;
- if (buffer_lap + 2 >= buffer_end)
- return false;
-
- *buffer_lap++ = '"';
- *buffer_lap = '\0';
- ctl_putdata(buf, (unsigned)(buffer_lap - buf), false);
- return true;
+ buffer = buf;
+ if (strlen(v->name) + 10 > sizeof(buf)) {
+ return; // really long var name
+ }
+ snprintf(buffer, sizeof(buf), "%s=\"", name);
+ buffer += strlen(buffer);
+
+ for ( ;!(EOV & v->flags); v++) {
+ length = strlen(v->name);
+ if (buffer+length+6 >= buf+sizeof(buf)) {
+ /* FIXME -- need bigger buffer */
+ continue;
+ }
+ if (first) {
+ first = false;
+ } else {
+ *buffer++ = ',';
+ }
+ memcpy(buffer, v->name, length);
+ buffer+= length;
+ }
+
+ *buffer++ = '"';
+ *buffer = '\0';
+ ctl_putdata(buf, (unsigned)(buffer - buf), false);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/879beeb26a40e9f86176045cecad5559769713f4
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/879beeb26a40e9f86176045cecad5559769713f4
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20240722/d4df1d11/attachment-0001.htm>
More information about the vc
mailing list