client: report invalid values in doffset and dfreq commands

This commit is contained in:
Miroslav Lichvar 2021-03-03 18:06:50 +01:00
parent c61ddb70da
commit 53501b743f

View file

@ -987,35 +987,41 @@ process_cmd_cmdaccheck(CMD_Request *msg, char *line)
/* ================================================== */ /* ================================================== */
static void static int
process_cmd_dfreq(CMD_Request *msg, char *line) process_cmd_dfreq(CMD_Request *msg, char *line)
{ {
double dfreq; double dfreq;
msg->command = htons(REQ_DFREQ); msg->command = htons(REQ_DFREQ);
if (sscanf(line, "%lf", &dfreq) == 1) {
msg->data.dfreq.dfreq = UTI_FloatHostToNetwork(dfreq); if (sscanf(line, "%lf", &dfreq) != 1) {
} else { LOG(LOGS_ERR, "Invalid value");
msg->data.dfreq.dfreq = UTI_FloatHostToNetwork(0.0); return 0;
} }
msg->data.dfreq.dfreq = UTI_FloatHostToNetwork(dfreq);
return 1;
} }
/* ================================================== */ /* ================================================== */
static void static int
process_cmd_doffset(CMD_Request *msg, char *line) process_cmd_doffset(CMD_Request *msg, char *line)
{ {
struct timeval tv; struct timeval tv;
double doffset; double doffset;
msg->command = htons(REQ_DOFFSET); msg->command = htons(REQ_DOFFSET);
if (sscanf(line, "%lf", &doffset) == 1) {
UTI_DoubleToTimeval(doffset, &tv); if (sscanf(line, "%lf", &doffset) != 1) {
msg->data.doffset.sec = htonl(tv.tv_sec); LOG(LOGS_ERR, "Invalid value");
msg->data.doffset.usec = htonl(tv.tv_usec); return 0;
} else {
msg->data.doffset.sec = htonl(0);
msg->data.doffset.usec = htonl(0);
} }
UTI_DoubleToTimeval(doffset, &tv);
msg->data.doffset.sec = htonl(tv.tv_sec);
msg->data.doffset.usec = htonl(tv.tv_usec);
return 1;
} }
/* ================================================== */ /* ================================================== */
@ -3267,12 +3273,12 @@ process_line(char *line)
do_normal_submit = process_cmd_deny(&tx_message, line); do_normal_submit = process_cmd_deny(&tx_message, line);
} }
} else if (!strcmp(command, "dfreq")) { } else if (!strcmp(command, "dfreq")) {
process_cmd_dfreq(&tx_message, line); do_normal_submit = process_cmd_dfreq(&tx_message, line);
} else if (!strcmp(command, "dns")) { } else if (!strcmp(command, "dns")) {
ret = process_cmd_dns(line); ret = process_cmd_dns(line);
do_normal_submit = 0; do_normal_submit = 0;
} else if (!strcmp(command, "doffset")) { } else if (!strcmp(command, "doffset")) {
process_cmd_doffset(&tx_message, line); do_normal_submit = process_cmd_doffset(&tx_message, line);
} else if (!strcmp(command, "dump")) { } else if (!strcmp(command, "dump")) {
process_cmd_dump(&tx_message, line); process_cmd_dump(&tx_message, line);
} else if (!strcmp(command, "exit")) { } else if (!strcmp(command, "exit")) {