commit:     2100df5c171029d6c347650fdaf098b67df0f059
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 14 06:35:35 2022 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Jun 14 06:35:35 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2100df5c

main: ensure correct parsing of key-value pairs in ini-files

Ensure the key is terminated when the '=' is adjacent to it (without
whitespace).

Bug: https://bugs.gentoo.org/851138
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 1337cb0..809a085 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <[email protected]>
@@ -747,7 +747,8 @@ read_one_repos_conf(const char *repos_conf, char **primary)
        repo = NULL;
        for (p = strtok_r(buf, "\n", &s); p != NULL; p = strtok_r(NULL, "\n", 
&s))
        {
-               /* trim trailing whitespace, remove comments, locate = */
+               /* trim trailing whitespace, remove comments, locate =, walking
+                * backwards to the front of the string */
                do_trim = true;
                e = NULL;
                for (r = q = s - 2; q >= p; q--) {
@@ -785,7 +786,7 @@ read_one_repos_conf(const char *repos_conf, char **primary)
                for (r = e - 1; r >= p && isspace((int)*r); r--)
                        *r = '\0';
                /* and after the = */
-               for (e++; e < q && isspace((int)*e); e++)
+               for (*e++ = '\0'; e < q && isspace((int)*e); e++)
                        ;
 
                if (is_default && strcmp(p, "main-repo") == 0) {

Reply via email to