teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0001-Fix-short-circuiting-of-version-strings-in-expressio.patch

Florian Festi 443474
From 321933f060896f721e361a1c8a8d3731bdcee827 Mon Sep 17 00:00:00 2001
Florian Festi 443474
From: Michael Schroeder <mls@suse.de>
Florian Festi 443474
Date: Wed, 22 Jun 2022 14:07:01 +0200
Florian Festi 443474
Subject: [PATCH] Fix short circuiting of version strings in expressions
Florian Festi 443474
Florian Festi 443474
We use an empty string when discarding a value due to short circuiting, but
Florian Festi 443474
an empty string is not allowed for versions. So use "0" in that case.
Florian Festi 443474
Florian Festi 443474
Fixes: #1883
Florian Festi 443474
---
Florian Festi 443474
 rpmio/expression.c | 2 +-
Florian Festi 443474
 tests/rpmmacro.at  | 2 ++
Florian Festi 443474
 2 files changed, 3 insertions(+), 1 deletion(-)
Florian Festi 443474
Florian Festi 443474
diff --git a/rpmio/expression.c b/rpmio/expression.c
Florian Festi 443474
index a389a04d5..98a44bbdb 100644
Florian Festi 443474
--- a/rpmio/expression.c
Florian Festi 443474
+++ b/rpmio/expression.c
Florian Festi 443474
@@ -477,7 +477,7 @@ static int rdToken(ParseState state)
Florian Festi 443474
       if (qtok == TOK_STRING) {
Florian Festi 443474
 	v = valueMakeString(temp);
Florian Festi 443474
       } else {
Florian Festi 443474
-	v = valueMakeVersion(temp);
Florian Festi 443474
+	v = valueMakeVersion(state->flags & RPMEXPR_DISCARD ? "0" : temp);
Florian Festi 443474
         free(temp); /* version doesn't take ownership of the string */
Florian Festi 443474
         if (v == 0) {
Florian Festi 443474
 	  exprErr(state, _("invalid version"), p+1);
Florian Festi 443474
diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at
Florian Festi 443474
index d1490b4d9..c4376d49e 100644
Florian Festi 443474
--- a/tests/rpmmacro.at
Florian Festi 443474
+++ b/tests/rpmmacro.at
Florian Festi 443474
@@ -533,6 +533,7 @@ runroot rpm \
Florian Festi 443474
     --eval '%["%{aaa}"]' \
Florian Festi 443474
     --eval '%[%{?ccc}]' \
Florian Festi 443474
     --eval '%[v"1:2.3-4"]' \
Florian Festi 443474
+    --eval '%[v"0" && v"0"]' \
Florian Festi 443474
 ]],
Florian Festi 443474
 [0],
Florian Festi 443474
 [4096
Florian Festi 443474
@@ -542,6 +543,7 @@ runroot rpm \
Florian Festi 443474
 5
Florian Festi 443474
 0
Florian Festi 443474
 1:2.3-4
Florian Festi 443474
+0
Florian Festi 443474
 ],
Florian Festi 443474
 [])
Florian Festi 443474
 AT_CLEANUP
Florian Festi 443474
-- 
Florian Festi 443474
2.41.0
Florian Festi 443474