teknoraver / rpms / rpm

Forked from rpms/rpm 5 months ago
Clone

Blame rpm-4.16.1.3-fix-patch-zero-semantics.patch

Michal Domonkos 216e68
From 2931047efc31f1288788bcdc8bd1d00b53cb9c76 Mon Sep 17 00:00:00 2001
Michal Domonkos 216e68
From: Panu Matilainen <pmatilai@redhat.com>
Michal Domonkos 216e68
Date: Wed, 30 Mar 2022 11:02:23 +0300
Michal Domonkos bcc1f9
Subject: [PATCH 1/3] Issue warning on implicit "%patch zero" variants,
Michal Domonkos 216e68
 sanitize semantics
Michal Domonkos 216e68
Michal Domonkos 216e68
Supporting `%patch` with no number specified, in particular combinations
Michal Domonkos 216e68
like `%patch 1` meaning patches 0 and 1 (!), prevents further progress
Michal Domonkos 216e68
in this area. Dropping support for these is a case of sawing off a limb
Michal Domonkos 216e68
to save the patient, but there's enough history to numberless `%patch`
Michal Domonkos 216e68
that we need to take the long route of deprecating it first.
Michal Domonkos 216e68
Michal Domonkos 216e68
To be exact:
Michal Domonkos 216e68
- we now issue a warning on `%patch` where no patch numbers have been
Michal Domonkos 216e68
  specified, but assume it to mean Patch0 for now
Michal Domonkos 216e68
- `%patch N' applies patch N and nothing else
Michal Domonkos 216e68
Michal Domonkos 216e68
While at it, avoid an unnecessary strdup() and a dangling buf after
Michal Domonkos 216e68
free.
Michal Domonkos 216e68
Michal Domonkos 216e68
(cherry picked from commit 02b8d8dccc0f045b0ebf81785cf6ad1056cf550e)
Michal Domonkos 216e68
---
Michal Domonkos 216e68
 build/parsePrep.c | 19 ++++++++-----------
Michal Domonkos 216e68
 1 file changed, 8 insertions(+), 11 deletions(-)
Michal Domonkos 216e68
Michal Domonkos 216e68
diff --git a/build/parsePrep.c b/build/parsePrep.c
Michal Domonkos 216e68
index d92e5cdf0..533de8a2c 100644
Michal Domonkos 216e68
--- a/build/parsePrep.c
Michal Domonkos 216e68
+++ b/build/parsePrep.c
Michal Domonkos 216e68
@@ -380,9 +380,7 @@ exit:
Michal Domonkos 216e68
  * - %patchN is equal to %patch -P\<N\>
Michal Domonkos 216e68
  * - -P\<N\> -P\<N+1\>... can be used to apply several patch on a single line
Michal Domonkos 216e68
  * - Any trailing arguments are treated as patch numbers
Michal Domonkos 216e68
- * - Any combination of the above, except unless at least one -P is specified,
Michal Domonkos 216e68
- *   %patch is treated as "numberless patch" so that "%patch 1" actually tries
Michal Domonkos 216e68
- *   to pull in numberless "Patch:" and numbered "Patch1:".
Michal Domonkos 216e68
+ * - Any combination of the above
Michal Domonkos 216e68
  *
Michal Domonkos 216e68
  * @param spec		build info
Michal Domonkos 216e68
  * @param line		current line from spec file
Michal Domonkos 216e68
@@ -420,15 +418,8 @@ static rpmRC doPatchMacro(rpmSpec spec, const char *line)
Michal Domonkos 216e68
     /* Convert %patchN to %patch -PN to simplify further processing */
Michal Domonkos 216e68
     if (! strchr(" \t\n", line[6])) {
Michal Domonkos 216e68
 	rasprintf(&buf, "%%patch -P %s", line + 6);
Michal Domonkos 216e68
-    } else {
Michal Domonkos 216e68
-	/* %patch without a number refers to patch 0 */
Michal Domonkos 216e68
-	if (strstr(line+6, " -P") == NULL)
Michal Domonkos 216e68
-	    rasprintf(&buf, "%%patch -P %d %s", 0, line + 6);
Michal Domonkos 216e68
-	else
Michal Domonkos 216e68
-	    buf = xstrdup(line);
Michal Domonkos 216e68
     }
Michal Domonkos 216e68
-    poptParseArgvString(buf, &argc, &argv);
Michal Domonkos 216e68
-    free(buf);
Michal Domonkos 216e68
+    poptParseArgvString(buf ? buf : line, &argc, &argv);
Michal Domonkos 216e68
 
Michal Domonkos 216e68
     /* 
Michal Domonkos 216e68
      * Grab all -P<N> numbers for later processing. Stored as strings
Michal Domonkos 216e68
@@ -459,6 +450,11 @@ static rpmRC doPatchMacro(rpmSpec spec, const char *line)
Michal Domonkos 216e68
     /* Any trailing arguments are treated as patch numbers */
Michal Domonkos 216e68
     argvAppend(&patchnums, (ARGV_const_t) poptGetArgs(optCon));
Michal Domonkos 216e68
 
Michal Domonkos 216e68
+    if (argvCount(patchnums) == 0) {
Michal Domonkos 216e68
+	rpmlog(RPMLOG_WARNING, _("Patch number not specified: %s\n"), line);
Michal Domonkos 216e68
+	argvAdd(&patchnums, "0");
Michal Domonkos 216e68
+    }
Michal Domonkos 216e68
+
Michal Domonkos 216e68
     /* Convert to number, generate patch command and append to %prep script */
Michal Domonkos 216e68
     for (patch = patchnums; *patch; patch++) {
Michal Domonkos 216e68
 	uint32_t pnum;
Michal Domonkos 216e68
@@ -484,6 +480,7 @@ exit:
Michal Domonkos 216e68
     free(opt_d);
Michal Domonkos 216e68
     free(opt_o);
Michal Domonkos 216e68
     free(argv);
Michal Domonkos 216e68
+    free(buf);
Michal Domonkos 216e68
     poptFreeContext(optCon);
Michal Domonkos 216e68
     return rc;
Michal Domonkos 216e68
 }
Michal Domonkos 216e68
-- 
Michal Domonkos 216e68
2.47.0
Michal Domonkos 216e68
Michal Domonkos 216e68
Michal Domonkos 216e68
From a8e821ff5c126613e13277bfd8b2050b71d1ea4e Mon Sep 17 00:00:00 2001
Michal Domonkos 216e68
From: Michal Domonkos <mdomonko@redhat.com>
Michal Domonkos 216e68
Date: Fri, 9 Aug 2024 11:57:47 +0200
Michal Domonkos bcc1f9
Subject: [PATCH 2/3] Safeguard against silent Patch0 omission
Michal Domonkos 216e68
Michal Domonkos 216e68
Commit 02b8d8dccc0f045b0ebf81785cf6ad1056cf550e fixed %patch so that it
Michal Domonkos 216e68
no longer applies Patch0 implicitly when used without the -P option.  A
Michal Domonkos 216e68
side effect of this is that, if a spec happens to rely on this quirky
Michal Domonkos 216e68
behavior, it will now skip Patch0 silently.
Michal Domonkos 216e68
Michal Domonkos 216e68
To prevent such silent regressions in existing packages, make explicit
Michal Domonkos 216e68
Patch0 application mandatory unless all %patch lines in the spec use the
Michal Domonkos 216e68
non-ambiguous syntax (i.e. %patchN, %patch -PN or %patch 0).
Michal Domonkos 216e68
Michal Domonkos 216e68
Basically, this reverts the above commit but replaces the original code
Michal Domonkos 216e68
with an error message.
Michal Domonkos 216e68
Michal Domonkos 216e68
Resolves: RHEL-6294
Michal Domonkos 216e68
---
Michal Domonkos 216e68
 build/parsePrep.c         | 16 ++++++++++++++++
Michal Domonkos 216e68
 build/rpmbuild_internal.h |  3 +++
Michal Domonkos 216e68
 build/spec.c              |  3 +++
Michal Domonkos 216e68
 3 files changed, 22 insertions(+)
Michal Domonkos 216e68
Michal Domonkos 216e68
diff --git a/build/parsePrep.c b/build/parsePrep.c
Michal Domonkos 216e68
index 533de8a2c..9d64c2141 100644
Michal Domonkos 216e68
--- a/build/parsePrep.c
Michal Domonkos 216e68
+++ b/build/parsePrep.c
Michal Domonkos 216e68
@@ -418,6 +418,10 @@ static rpmRC doPatchMacro(rpmSpec spec, const char *line)
Michal Domonkos 216e68
     /* Convert %patchN to %patch -PN to simplify further processing */
Michal Domonkos 216e68
     if (! strchr(" \t\n", line[6])) {
Michal Domonkos 216e68
 	rasprintf(&buf, "%%patch -P %s", line + 6);
Michal Domonkos 216e68
+    } else {
Michal Domonkos 216e68
+	/* %patch without a number used to refer to patch 0 */
Michal Domonkos 216e68
+	if (strstr(line+6, " -P") == NULL)
Michal Domonkos 216e68
+	    spec->patch0_implicit = line;
Michal Domonkos 216e68
     }
Michal Domonkos 216e68
     poptParseArgvString(buf ? buf : line, &argc, &argv);
Michal Domonkos 216e68
 
Michal Domonkos 216e68
@@ -464,6 +468,8 @@ static rpmRC doPatchMacro(rpmSpec spec, const char *line)
Michal Domonkos 216e68
 		     *patch, line);
Michal Domonkos 216e68
 	    goto exit;
Michal Domonkos 216e68
 	}
Michal Domonkos 216e68
+	if (pnum == 0)
Michal Domonkos 216e68
+	    spec->patch0_explicit = line;
Michal Domonkos 216e68
 	s = doPatch(spec, pnum, opt_p, opt_b, opt_R, opt_E, opt_F, opt_d, opt_o, opt_Z);
Michal Domonkos 216e68
 	if (s == NULL) {
Michal Domonkos 216e68
 	    goto exit;
Michal Domonkos 216e68
@@ -516,8 +522,18 @@ int parsePrep(rpmSpec spec)
Michal Domonkos 216e68
 	}
Michal Domonkos 216e68
     }
Michal Domonkos 216e68
 
Michal Domonkos 216e68
+    if (spec->patch0_implicit && !spec->patch0_explicit &&
Michal Domonkos 216e68
+	    findSource(spec, 0, RPMBUILD_ISPATCH)) {
Michal Domonkos 216e68
+	rpmlog(RPMLOG_ERR, _("Patch0 no longer applied implicitly, pass 0 or -P0: %s\n"),
Michal Domonkos 216e68
+	       spec->patch0_implicit);
Michal Domonkos 216e68
+	res = PART_ERROR;
Michal Domonkos 216e68
+	goto exit;
Michal Domonkos 216e68
+    }
Michal Domonkos 216e68
+
Michal Domonkos 216e68
 exit:
Michal Domonkos 216e68
     argvFree(saveLines);
Michal Domonkos 216e68
+    spec->patch0_implicit = NULL;
Michal Domonkos 216e68
+    spec->patch0_explicit = NULL;
Michal Domonkos 216e68
 
Michal Domonkos 216e68
     return res;
Michal Domonkos 216e68
 }
Michal Domonkos 216e68
diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h
Michal Domonkos 216e68
index 797d27744..545cc1f43 100644
Michal Domonkos 216e68
--- a/build/rpmbuild_internal.h
Michal Domonkos 216e68
+++ b/build/rpmbuild_internal.h
Michal Domonkos 216e68
@@ -132,6 +132,9 @@ struct rpmSpec_s {
Michal Domonkos 216e68
     int autonum_patch;
Michal Domonkos 216e68
     int autonum_source;
Michal Domonkos 216e68
 
Michal Domonkos 216e68
+    const char *patch0_implicit;
Michal Domonkos 216e68
+    const char *patch0_explicit;
Michal Domonkos 216e68
+
Michal Domonkos 216e68
     char * sourceRpmName;
Michal Domonkos 216e68
     unsigned char * sourcePkgId;
Michal Domonkos 216e68
     Package sourcePackage;
Michal Domonkos 216e68
diff --git a/build/spec.c b/build/spec.c
Michal Domonkos 216e68
index 6d402319f..72f0d25bd 100644
Michal Domonkos 216e68
--- a/build/spec.c
Michal Domonkos 216e68
+++ b/build/spec.c
Michal Domonkos 216e68
@@ -232,6 +232,9 @@ rpmSpec newSpec(void)
Michal Domonkos 216e68
     spec->autonum_patch = -1;
Michal Domonkos 216e68
     spec->autonum_source = -1;
Michal Domonkos 216e68
 
Michal Domonkos 216e68
+    spec->patch0_implicit = NULL;
Michal Domonkos 216e68
+    spec->patch0_explicit = NULL;
Michal Domonkos 216e68
+
Michal Domonkos 216e68
     spec->sourceRpmName = NULL;
Michal Domonkos 216e68
     spec->sourcePkgId = NULL;
Michal Domonkos 216e68
     spec->sourcePackage = NULL;
Michal Domonkos 216e68
-- 
Michal Domonkos 216e68
2.47.0
Michal Domonkos 216e68
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
From 896c7e37d65b1019cc179abcf9524807ba2006d2 Mon Sep 17 00:00:00 2001
Michal Domonkos bcc1f9
From: Michal Domonkos <mdomonko@redhat.com>
Michal Domonkos bcc1f9
Date: Wed, 6 Nov 2024 16:10:53 +0100
Michal Domonkos bcc1f9
Subject: [PATCH 3/3] Improve newly added %patch warning/error messages
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
Make it obvious that the numberless %patch syntax is now *deprecated*
Michal Domonkos bcc1f9
(and thus no longer works in RHEL-10).
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
Also suggest an actual fix to the user (in both messages), much like we
Michal Domonkos bcc1f9
have for the %patchN warning in RPM 4.19 (see commit
Michal Domonkos bcc1f9
eb5ece1267a22330f6116149997cf5cc1c22b21f).
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
Kudos to Eva Mrakova for noticing & suggesting this.
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
Related: RHEL-6294
Michal Domonkos bcc1f9
---
Michal Domonkos bcc1f9
 build/parsePrep.c | 7 ++++---
Michal Domonkos bcc1f9
 1 file changed, 4 insertions(+), 3 deletions(-)
Michal Domonkos bcc1f9
Michal Domonkos bcc1f9
diff --git a/build/parsePrep.c b/build/parsePrep.c
Michal Domonkos bcc1f9
index 9d64c2141..63014ea89 100644
Michal Domonkos bcc1f9
--- a/build/parsePrep.c
Michal Domonkos bcc1f9
+++ b/build/parsePrep.c
Michal Domonkos bcc1f9
@@ -455,7 +455,8 @@ static rpmRC doPatchMacro(rpmSpec spec, const char *line)
Michal Domonkos bcc1f9
     argvAppend(&patchnums, (ARGV_const_t) poptGetArgs(optCon));
Michal Domonkos bcc1f9
 
Michal Domonkos bcc1f9
     if (argvCount(patchnums) == 0) {
Michal Domonkos bcc1f9
-	rpmlog(RPMLOG_WARNING, _("Patch number not specified: %s\n"), line);
Michal Domonkos bcc1f9
+	rpmlog(RPMLOG_WARNING, _("%%patch (without a number) is deprecated, "
Michal Domonkos bcc1f9
+				 "add 0 (or -P 0): %s\n"), line);
Michal Domonkos bcc1f9
 	argvAdd(&patchnums, "0");
Michal Domonkos bcc1f9
     }
Michal Domonkos bcc1f9
 
Michal Domonkos bcc1f9
@@ -524,8 +525,8 @@ int parsePrep(rpmSpec spec)
Michal Domonkos bcc1f9
 
Michal Domonkos bcc1f9
     if (spec->patch0_implicit && !spec->patch0_explicit &&
Michal Domonkos bcc1f9
 	    findSource(spec, 0, RPMBUILD_ISPATCH)) {
Michal Domonkos bcc1f9
-	rpmlog(RPMLOG_ERR, _("Patch0 no longer applied implicitly, pass 0 or -P0: %s\n"),
Michal Domonkos bcc1f9
-	       spec->patch0_implicit);
Michal Domonkos bcc1f9
+	rpmlog(RPMLOG_ERR, _("%%patch N no longer applies Patch0 implicitly, "
Michal Domonkos bcc1f9
+			     "add 0 (or -P 0): %s\n"), spec->patch0_implicit);
Michal Domonkos bcc1f9
 	res = PART_ERROR;
Michal Domonkos bcc1f9
 	goto exit;
Michal Domonkos bcc1f9
     }
Michal Domonkos bcc1f9
-- 
Michal Domonkos bcc1f9
2.47.0
Michal Domonkos bcc1f9