From 356771c0c3c2b8040ba2ae83394460d1402d487b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 3 May 2022 13:25:11 +0200 Subject: [PATCH] client: rework command catenation Use snprintf() instead of strcat() and don't try to parse commands longer than 2048 characters to make it consistent with the chrony.conf parser, avoid memory allocation, and not rely on the system ARG_MAX to keep the length sane. --- client.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/client.c b/client.c index a2c780fd..242bd6df 100644 --- a/client.c +++ b/client.c @@ -3245,37 +3245,30 @@ process_line(char *line) /* ================================================== */ +#define MAX_LINE_LENGTH 2048 + static int process_args(int argc, char **argv, int multi) { - int total_length, i, ret = 0; - char *line; - - total_length = 0; - for(i=0; i= sizeof (line)) { + LOG(LOGS_ERR, "Command too long"); + return 0; } + if (!multi && i + 1 < argc) + continue; + ret = process_line(line); if (!ret || quit) break; - } - Free(line); + l = 0; + } return ret; } -- 2.47.2