]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
devtool: reset: Escape command line input used in regular expression
authorPeter Kjellerstedt <pkj@axis.com>
Tue, 18 Mar 2025 23:25:39 +0000 (00:25 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 20 Mar 2025 11:29:00 +0000 (11:29 +0000)
Running, e.g., `devtool reset sdbus-c++` would result in the following
error:

  re.error: multiple repeat at position 35

This was due to the ++ in the recipe name, which would be treated as an
incorrect regular expression in _reset().

Use re.escape() to make sure all characters in the recipe name are
treated literally.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta-selftest/recipes-test/devtool/devtool-test-reset-re++.bb [new file with mode: 0644]
meta-selftest/recipes-test/devtool/devtool-test-reset-re++/file1 [new file with mode: 0644]
meta/lib/oeqa/selftest/cases/devtool.py
scripts/lib/devtool/standard.py

diff --git a/meta-selftest/recipes-test/devtool/devtool-test-reset-re++.bb b/meta-selftest/recipes-test/devtool/devtool-test-reset-re++.bb
new file mode 100644 (file)
index 0000000..35672a5
--- /dev/null
@@ -0,0 +1,9 @@
+LICENSE = "CLOSED"
+INHIBIT_DEFAULT_DEPS = "1"
+
+SRC_URI = "file://file1"
+
+S = "${WORKDIR}/sources"
+UNPACKDIR = "${S}"
+
+EXCLUDE_FROM_WORLD = "1"
diff --git a/meta-selftest/recipes-test/devtool/devtool-test-reset-re++/file1 b/meta-selftest/recipes-test/devtool/devtool-test-reset-re++/file1
new file mode 100644 (file)
index 0000000..51f466f
--- /dev/null
@@ -0,0 +1 @@
+A file
index 115dc24d87e13542b235321bf0e8aca1cfab9f38..ddbc554af010dc3a8a82bf2c7ac1ed8ebbbaea2a 100644 (file)
@@ -1757,6 +1757,8 @@ class DevtoolExtractTests(DevtoolBase):
         self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
         self._check_src_repo(tempdir)
 
+class DevtoolResetTests(DevtoolBase):
+
     def test_devtool_reset_all(self):
         tempdir = tempfile.mkdtemp(prefix='devtoolqa')
         self.track_for_cleanup(tempdir)
@@ -1783,6 +1785,21 @@ class DevtoolExtractTests(DevtoolBase):
         matches2 = glob.glob(stampprefix2 + '*')
         self.assertFalse(matches2, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe2)
 
+    def test_devtool_reset_re_plus_plus(self):
+        tempdir = tempfile.mkdtemp(prefix='devtoolqa')
+        self.track_for_cleanup(tempdir)
+        self.track_for_cleanup(self.workspacedir)
+        self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
+        testrecipe = 'devtool-test-reset-re++'
+        result = runCmd('devtool modify %s' % testrecipe)
+        result = runCmd('devtool reset -n %s' % testrecipe)
+        self.assertIn(testrecipe, result.output)
+        result = runCmd('devtool status')
+        self.assertNotIn(testrecipe, result.output)
+        self.assertNotExists(os.path.join(self.workspacedir, 'recipes', testrecipe), 'Recipe directory should not exist after resetting')
+
+class DevtoolDeployTargetTests(DevtoolBase):
+
     @OETestTag("runqemu")
     def test_devtool_deploy_target(self):
         self._check_runqemu_prerequisites()
@@ -1850,6 +1867,8 @@ class DevtoolExtractTests(DevtoolBase):
             result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand), ignore_status=True)
             self.assertNotEqual(result, 0, 'undeploy-target did not remove command as it should have')
 
+class DevtoolBuildImageTests(DevtoolBase):
+
     def test_devtool_build_image(self):
         """Test devtool build-image plugin"""
         # Check preconditions
index 0cdb9c6cfb9499d52f42582d3e8812421154c05c..cdfdba43eef135e76a42f8cdbde31770d3de8cb9 100644 (file)
@@ -1951,7 +1951,7 @@ def _reset(recipes, no_clean, remove_work, config, basepath, workspace):
             lines = f.readlines()
             with open(new_layerconf_file, 'a') as nf:
                 for line in lines:
-                    pprovider_exp = r'^PREFERRED_PROVIDER_.*? = "' + pn + r'"$'
+                    pprovider_exp = r'^PREFERRED_PROVIDER_.*? = "' + re.escape(pn) + r'"$'
                     if not re.match(pprovider_exp, line):
                         nf.write(line)
                     else: