[pacman-dev] [PATCH] use strtok_r to parse multi-value config options
This prevents multiple spaces between values from being parsed as empty values. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/conf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1bea2b0..d407296 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -373,17 +373,14 @@ static int process_cleanmethods(alpm_list_t *values, static void setrepeatingoption(char *ptr, const char *option, alpm_list_t **list) { - char *q; + char *val, *saveptr; - while((q = strchr(ptr, ' '))) { - *q = '\0'; - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); - ptr = q; - ptr++; + val = strtok_r(ptr, " ", &saveptr); + while(val) { + *list = alpm_list_add(*list, strdup(val)); + pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, val); + val = strtok_r(NULL, " ", &saveptr); } - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); } static int _parse_options(const char *key, char *value, -- 1.8.1.2
On Sat, Feb 02, 2013 at 10:16:19AM -0500, Andrew Gregory wrote:
This prevents multiple spaces between values from being parsed as empty values.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/conf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1bea2b0..d407296 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -373,17 +373,14 @@ static int process_cleanmethods(alpm_list_t *values, static void setrepeatingoption(char *ptr, const char *option, alpm_list_t **list) { - char *q; + char *val, *saveptr;
- while((q = strchr(ptr, ' '))) { - *q = '\0'; - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); - ptr = q; - ptr++;
It'd be nice to see if there's any history on why this function was written this way (as to avoid modifying the input string).
+ val = strtok_r(ptr, " ", &saveptr); + while(val) { + *list = alpm_list_add(*list, strdup(val)); + pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, val); + val = strtok_r(NULL, " ", &saveptr); } - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); }
static int _parse_options(const char *key, char *value, -- 1.8.1.2
On Sat, 2 Feb 2013 12:39:11 -0500 Dave Reisner <d@falconindy.com> wrote:
On Sat, Feb 02, 2013 at 10:16:19AM -0500, Andrew Gregory wrote:
This prevents multiple spaces between values from being parsed as empty values.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/conf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1bea2b0..d407296 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -373,17 +373,14 @@ static int process_cleanmethods(alpm_list_t *values, static void setrepeatingoption(char *ptr, const char *option, alpm_list_t **list) { - char *q; + char *val, *saveptr;
- while((q = strchr(ptr, ' '))) { - *q = '\0'; - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); - ptr = q; - ptr++;
It'd be nice to see if there's any history on why this function was written this way (as to avoid modifying the input string).
Just to be clear, the current version modifies it as well. As for why... I have no idea. It goes all the way back to the initial commit.
+ val = strtok_r(ptr, " ", &saveptr); + while(val) { + *list = alpm_list_add(*list, strdup(val)); + pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, val); + val = strtok_r(NULL, " ", &saveptr); } - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); }
static int _parse_options(const char *key, char *value, -- 1.8.1.2
On 03/02/13 04:01, Andrew Gregory wrote:
On Sat, 2 Feb 2013 12:39:11 -0500 Dave Reisner <d@falconindy.com> wrote:
On Sat, Feb 02, 2013 at 10:16:19AM -0500, Andrew Gregory wrote:
This prevents multiple spaces between values from being parsed as empty values.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- src/pacman/conf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1bea2b0..d407296 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -373,17 +373,14 @@ static int process_cleanmethods(alpm_list_t *values, static void setrepeatingoption(char *ptr, const char *option, alpm_list_t **list) { - char *q; + char *val, *saveptr;
- while((q = strchr(ptr, ' '))) { - *q = '\0'; - *list = alpm_list_add(*list, strdup(ptr)); - pm_printf(ALPM_LOG_DEBUG, "config: %s: %s\n", option, ptr); - ptr = q; - ptr++;
It'd be nice to see if there's any history on why this function was written this way (as to avoid modifying the input string).
Just to be clear, the current version modifies it as well. As for why... I have no idea. It goes all the way back to the initial commit.
I'd say it is an oversight. With actual consequences: [09:37:59] debug: config: SigLevel: Required [09:37:59] debug: config: SigLevel: DatabaseOptional [09:37:59] debug: config: SigLevel: [09:37:59] debug: config: SigLevel: TrustedOnly [09:37:59] error: config file /etc/pacman.conf, line 22: invalid value for 'SigLevel' : '' Allan
participants (3)
-
Allan McRae
-
Andrew Gregory
-
Dave Reisner