Skip to contentSkip to conversation

tst_kvcmp: Strip double quotes when parsing /etc/os-release

PATCH New Petr Vorel 3 participants 5 messages Aug 20, 2020 – Aug 21, 2020 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v3 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release

ID is normally without double quotes, e.g.: ID=debian

But at least SLES and openSUSE contain double quotes, e.g.:
ID="opensuse-tumbleweed"

thus optionally strip the double quotes after scanning them.

Fixes e2e60a39b ("lib/tst_kvercmp: Add support /etc/os-release")
---
 lib/tst_kvercmp.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
lib/tst_kvercmp.c +11 -1
index 185a5c39c..5d56e30b9 100644
@@ -131,6 +131,7 @@ int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
 const char *tst_kvcmp_distname(const char *kver)
 {
 	static char distname[64];
+	char *ret = distname;
 	char *p = distname;
 
 	if (strstr(kver, ".el5uek"))
@@ -148,12 +149,21 @@ const char *tst_kvcmp_distname(const char *kver)
 	if (access(OSRELEASE_PATH, F_OK) != -1) {
 		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
 
+		if (p[0] == '"') {
+			ret = distname + 1;
+			p = ret;
+		}
+
 		while (*p) {
+			if (*p == '"') {
+				*p = 0;
+				break;
+			}
 			*p = toupper((unsigned char)*p);
 			p++;
 		}
 
-		return distname;
+		return ret;
 	}
 
 	return NULL;
Signature · 1 line
2.28.0
#2 lore raw

PATCH v3 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release

LGTM,
Tested with crafted ID, it can correctly parse the ID with or without the double quote.

Another thing to note is that I found the loop in tst_kvercmp2 could iterate outside the size of "vers" and causing tst_test.c:1298: BROK: Test killed by SIGSEGV!

Quoted 9 lines · Cyril Hrubis

Hi!
Looks good to me.

--
Cyril Hrubis
[email protected]

author
#3 lore raw

PATCH v3 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release

Hi Po-Hsu,

Quoted 7 lines

LGTM,
Tested with crafted ID, it can correctly parse the ID with or without the double quote.

Another thing to note is that I found the loop in tst_kvercmp2 could iterate outside the size of "vers" and causing tst_test.c:1298: BROK: Test killed by SIGSEGV!

Will you post the patch for this?

Quoted 1 line

I'm sorry, I've merged it before, but forget to notify. Is the bug mentioned above related to my commit?

Kind regards,
Petr

#4 lore raw

PATCH v3 1/1 tst_kvcmp: Strip double quotes when parsing /etc/os-release

Quoted 7 lines · Petr Vorel

Hi Po-Hsu,

Quoted 3 lines

LGTM,
Tested with crafted ID, it can correctly parse the ID with or without the double quote.

Quoted 8 lines
Quoted 3 lines

Another thing to note is that I found the loop in tst_kvercmp2 could iterate outside the size of "vers" and causing tst_test.c:1298: BROK: Test killed by SIGSEGV!

Will you post the patch for this?

Quoted 1 line

I'm sorry, I've merged it before, but forget to notify. Is the bug mentioned above related to my commit?

Hello Petr,
Don't worry it's not related to this commit :)
I will have a look at that bug.

Cheers

Quoted 3 lines

Kind regards,
Petr