From ef7d48365534ed92e607d83be84069c725fc83d4 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Thu, 11 Jul 2024 16:54:06 +0300 Subject: [PATCH 1/6] fix: Allow inline comments in clamd.conf --- common/optparser.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index dd99f43eb2..e89ecbd189 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -62,9 +62,9 @@ #define MAXCMDOPTS 150 -#define MATCH_NUMBER "^[0-9]+$" -#define MATCH_SIZE "^[0-9]+[KMG]?$" -#define MATCH_BOOL "^(yes|true|1|no|false|0)$" +#define MATCH_NUMBER "^[0-9]+((( +)?#(.*))?)$" +#define MATCH_SIZE "^[0-9]+[KMG]?(( +)?#(.*))?$" +#define MATCH_BOOL "^(yes|true|1|no|false|0)(( +)?#(.*))?$" #define FLAG_MULTIPLE 1 /* option can be used multiple times */ #define FLAG_REQUIRED 2 /* arg is required, even if there's a default value */ @@ -931,6 +931,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo regex_t regex; long long numarg, lnumarg, lnumlimit; int regflags = REG_EXTENDED | REG_NOSUB; + const char* inlinecomment = NULL; #ifdef _WIN32 if (!is_initialized) { @@ -1187,6 +1188,10 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } numarg = -1; + inlinecomment = strchr(arg, '#'); + if (inlinecomment != NULL) { + arg = strtok(arg, "#"); + } switch (optentry->argtype) { case CLOPT_TYPE_STRING: if (!arg) From 8e9d15f37faa16b1f40a8b44c6fa6aa6cc89e206 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Thu, 11 Jul 2024 16:54:06 +0300 Subject: [PATCH 2/6] fix: Allow inline comments in clamd.conf --- common/optparser.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index bbf3bfa2f6..918d63560a 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -62,9 +62,9 @@ #define MAXCMDOPTS 150 -#define MATCH_NUMBER "^[0-9]+$" -#define MATCH_SIZE "^[0-9]+[KMG]?$" -#define MATCH_BOOL "^(yes|true|1|no|false|0)$" +#define MATCH_NUMBER "^[0-9]+((( +)?#(.*))?)$" +#define MATCH_SIZE "^[0-9]+[KMG]?(( +)?#(.*))?$" +#define MATCH_BOOL "^(yes|true|1|no|false|0)(( +)?#(.*))?$" #define FLAG_MULTIPLE 1 /* option can be used multiple times */ #define FLAG_REQUIRED 2 /* arg is required, even if there's a default value */ @@ -932,6 +932,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo regex_t regex; long long numarg, lnumarg, lnumlimit; int regflags = REG_EXTENDED | REG_NOSUB; + const char* inlinecomment = NULL; #ifdef _WIN32 if (!is_initialized) { @@ -1188,6 +1189,10 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } numarg = -1; + inlinecomment = strchr(arg, '#'); + if (inlinecomment != NULL) { + arg = strtok(arg, "#"); + } switch (optentry->argtype) { case CLOPT_TYPE_STRING: if (!arg) From 71f56ce3ec928890a5e21143196253cfcc98bf33 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 14 Jan 2025 11:25:26 +0200 Subject: [PATCH 3/6] Trim trailing spaces and run clang-format. --- common/optparser.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index e89ecbd189..2431900ea2 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -930,8 +930,8 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo char shortopts[MAXCMDOPTS]; regex_t regex; long long numarg, lnumarg, lnumlimit; - int regflags = REG_EXTENDED | REG_NOSUB; - const char* inlinecomment = NULL; + int regflags = REG_EXTENDED | REG_NOSUB; + const char *inlinecomment = NULL; #ifdef _WIN32 if (!is_initialized) { @@ -1013,8 +1013,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo break; buff = buffer; - for (i = 0; i < (int)strlen(buff) - 1 && (buff[i] == ' ' || buff[i] == '\t'); i++) - ; + for (i = 0; i < (int)strlen(buff) - 1 && (buff[i] == ' ' || buff[i] == '\t'); i++); buff += i; line++; if (strlen(buff) <= 2 || buff[0] == '#') @@ -1035,11 +1034,9 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } name = buff; *pt++ = 0; - for (i = 0; i < (int)strlen(pt) - 1 && (pt[i] == ' ' || pt[i] == '\t'); i++) - ; + for (i = 0; i < (int)strlen(pt) - 1 && (pt[i] == ' ' || pt[i] == '\t'); i++); pt += i; - for (i = strlen(pt); i >= 1 && (pt[i - 1] == ' ' || pt[i - 1] == '\t' || pt[i - 1] == '\n'); i--) - ; + for (i = strlen(pt); i >= 1 && (pt[i - 1] == ' ' || pt[i - 1] == '\t' || pt[i - 1] == '\n'); i--); if (!i) { if (verbose) fprintf(stderr, "ERROR: Missing argument for option at %s:%d\n", cfgfile, line); @@ -1187,10 +1184,14 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } } - numarg = -1; + numarg = -1; inlinecomment = strchr(arg, '#'); if (inlinecomment != NULL) { - arg = strtok(arg, "#"); + arg = strtok(arg, "#"); + char *p2 = NULL; + p2 = arg + strlen(arg) - 1; + while (p2 >= arg && *p2 == ' ') + *(p2--) = '\0'; } switch (optentry->argtype) { case CLOPT_TYPE_STRING: From f26b10e5302c20a71ff341983a2353e5adcdd0ed Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 14 Jan 2025 11:40:03 +0200 Subject: [PATCH 4/6] Move variable used for trimming outside the while loop --- common/optparser.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index 2431900ea2..67466ce7b9 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -932,6 +932,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo long long numarg, lnumarg, lnumlimit; int regflags = REG_EXTENDED | REG_NOSUB; const char *inlinecomment = NULL; + char *trim_comment; #ifdef _WIN32 if (!is_initialized) { @@ -1187,11 +1188,10 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo numarg = -1; inlinecomment = strchr(arg, '#'); if (inlinecomment != NULL) { - arg = strtok(arg, "#"); - char *p2 = NULL; - p2 = arg + strlen(arg) - 1; - while (p2 >= arg && *p2 == ' ') - *(p2--) = '\0'; + arg = strtok(arg, "#"); + trim_comment = arg + strlen(arg) - 1; + while (trim_comment >= arg && *trim_comment == ' ') + *(trim_comment--) = '\0'; } switch (optentry->argtype) { case CLOPT_TYPE_STRING: From 07dfde083f59a475d3da71c8f732a2f18bc4dfec Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 14 Jan 2025 12:03:31 +0200 Subject: [PATCH 5/6] remove merge markers --- common/optparser.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index b8a2eae49b..bec0e6508b 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -931,14 +931,9 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo char shortopts[MAXCMDOPTS]; regex_t regex; long long numarg, lnumarg, lnumlimit; -<<<<<<< HEAD int regflags = REG_EXTENDED | REG_NOSUB; const char *inlinecomment = NULL; char *trim_comment; -======= - int regflags = REG_EXTENDED | REG_NOSUB; - const char* inlinecomment = NULL; ->>>>>>> 8e9d15f37faa16b1f40a8b44c6fa6aa6cc89e206 #ifdef _WIN32 if (!is_initialized) { @@ -1191,7 +1186,6 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } } -<<<<<<< HEAD numarg = -1; inlinecomment = strchr(arg, '#'); if (inlinecomment != NULL) { @@ -1199,12 +1193,6 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo trim_comment = arg + strlen(arg) - 1; while (trim_comment >= arg && *trim_comment == ' ') *(trim_comment--) = '\0'; -======= - numarg = -1; - inlinecomment = strchr(arg, '#'); - if (inlinecomment != NULL) { - arg = strtok(arg, "#"); ->>>>>>> 8e9d15f37faa16b1f40a8b44c6fa6aa6cc89e206 } switch (optentry->argtype) { case CLOPT_TYPE_STRING: From 971f3e72d4d57d335e459b731493c3ee1b7b1660 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Tue, 14 Jan 2025 12:08:28 +0200 Subject: [PATCH 6/6] Return for-s to their previous format. --- common/optparser.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/optparser.c b/common/optparser.c index bec0e6508b..44beaba484 100644 --- a/common/optparser.c +++ b/common/optparser.c @@ -1015,7 +1015,8 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo break; buff = buffer; - for (i = 0; i < (int)strlen(buff) - 1 && (buff[i] == ' ' || buff[i] == '\t'); i++); + for (i = 0; i < (int)strlen(buff) - 1 && (buff[i] == ' ' || buff[i] == '\t'); i++) + ; buff += i; line++; if (strlen(buff) <= 2 || buff[0] == '#') @@ -1036,9 +1037,11 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo } name = buff; *pt++ = 0; - for (i = 0; i < (int)strlen(pt) - 1 && (pt[i] == ' ' || pt[i] == '\t'); i++); + for (i = 0; i < (int)strlen(pt) - 1 && (pt[i] == ' ' || pt[i] == '\t'); i++) + ; pt += i; - for (i = strlen(pt); i >= 1 && (pt[i - 1] == ' ' || pt[i - 1] == '\t' || pt[i - 1] == '\n'); i--); + for (i = strlen(pt); i >= 1 && (pt[i - 1] == ' ' || pt[i - 1] == '\t' || pt[i - 1] == '\n'); i--) + ; if (!i) { if (verbose) fprintf(stderr, "ERROR: Missing argument for option at %s:%d\n", cfgfile, line);