Skip to contentSkip to conversation

configure: disallow spaces and colons in source path and build path

PATCH Superseded Antonio Ospite 5 participants 12 messages May 3, 2019 – May 22, 2019 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover configure: disallow spaces and colons in source path and build path

Hi,

Here is a v2 patch set to address
https://bugs.launchpad.net/qemu/+bug/1817345

The series follows up to:
https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg05290.html
https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg05573.html

Changes since v1:
- Add a preparatory patch to set source_path only once and in a more robust way.

- Move the checks in configure after the source_path definition to avoid using realpath which is not available everywhere.

- Cover also the build path in Makefile. An extensive explanation of why I think this is needed is here:
https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg05398.html

Thanks,
Antonio

Antonio Ospite (2):
configure: set source_path only once and make its definition more
robust
configure: disallow spaces and colons in source path and build path

 Makefile  |  4 ++++
 configure | 12 +++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
Signature · 7 lines
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
#1 lore raw

PATCH v2 1/2 configure: set source_path only once and make its definition more robust

From: Antonio Ospite <[email protected]>

Since commit 79d77bcd36 (configure: Remove --source-path option, 2019-04-29) source_path cannot be overridden anymore, move it out of the "default parameters" block since the word "default" may suggest that the value can change, while in fact it does not.

While at it, only set source_path once and separate the positional argument of basename with "--" to more robustly cover the case of path names starting with a dash.

---
 configure | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
configure +3 -3
index 60719ddcc5..9832cbca5c 100755
@@ -276,10 +276,10 @@ ld_has() {
     $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1
 }
 
-# default parameters
-source_path=$(dirname "$0")
 # make source path absolute
-source_path=$(cd "$source_path"; pwd)
+source_path=$(cd "$(dirname -- "$0")"; pwd)
+
+# default parameters
 cpu=""
 iasl="iasl"
 interp_prefix="/usr/gnemul/qemu-%M"
Signature · 1 line
2.20.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] configure: set source_path only once and make its definition more robust

Quoted 7 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

Since commit 79d77bcd36 (configure: Remove --source-path option, 2019-04-29) source_path cannot be overridden anymore, move it out of the "default parameters" block since the word "default" may suggest that the value can change, while in fact it does not.

Quoted 9 lines

While at it, only set source_path once and separate the positional argument of basename with "--" to more robustly cover the case of path names starting with a dash.

---
 configure | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

PATCH v2 2/2 configure: disallow spaces and colons in source path and build path

In reply to Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
 Makefile  | 4 ++++
 configure | 6 ++++++
 2 files changed, 10 insertions(+)
Makefile +4 -0
index 1211e78c91..7f3f7a7fef 100644
@@ -1,5 +1,9 @@
 # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
configure +6 -0
index 9832cbca5c..f7ad4381bd 100755
@@ -279,6 +279,12 @@ ld_has() {
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";
+then
+  error_exit "main directory cannot contain spaces nor colons"
+fi
+
 # default parameters
 cpu=""
 iasl="iasl"
Signature · 1 line
2.20.1
Reviewed-by on v2 2/2
#4 lore raw
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
 Makefile  | 4 ++++
 configure | 6 ++++++
 2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
 # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw
Quoted 45 lines · On Mon, 6 May 2019 12:27:46 -0500 Eric Blake <[email protected]> wrote:
Quoted 44 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
 Makefile  | 4 ++++
 configure | 6 ++++++
 2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
 # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755
@@ -279,6 +279,12 @@ ld_has() {
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
 
Quoted 7 lines

configure ld_has() { · line 283

Quoted 2 lines
configure +2 -0
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

I always forget about this printf feature :)

Quoted 3 lines

but that's trivial enough for a maintainer to fold in if desired.

Thanks,
Antonio

Signature · 7 lines
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
#6 lore raw
In reply to Eric Blake
Quoted 51 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
 Makefile  | 4 ++++
 configure | 6 ++++++
 2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
 # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
 # make source path absolute
 source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

Quoted 5 lines

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

What tree is this going to go in via? I suggest the -trivial tree.

thanks
-- PMM

#7 lore raw
Quoted 52 lines · Peter Maydell
Quoted 51 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
  Makefile  | 4 ++++
  configure | 6 ++++++
  2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
  # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
  # Always point to the root of the build tree (needs GNU make).
  BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
  # make source path absolute
  source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

Quoted 8 lines
Quoted 5 lines

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

What tree is this going to go in via? I suggest the -trivial tree.

Applied (unchanged) to my trivial-patches branch.

Thanks,
Laurent

#8 lore raw
Quoted 57 lines · Laurent Vivier
Quoted 56 lines · Peter Maydell
Quoted 55 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
  Makefile  | 4 ++++
  configure | 6 ++++++

  2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
   # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
   # Always point to the root of the build tree (needs GNU make).
   BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
   # make source path absolute
   source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What tree is this going to go in via? I suggest the -trivial tree.

Applied (unchanged) to my trivial-patches branch.

Thank you Laurent.

I'll think about sending a followup patch with the changes proposed by Eric and I'll CC you if I do.

Ciao,
Antonio

#9 lore raw
Quoted 64 lines · Antonio Ospite
Quoted 63 lines · Laurent Vivier
Quoted 60 lines · Peter Maydell
Quoted 51 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
  Makefile  | 4 ++++
  configure | 6 ++++++

  2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
   # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
   # Always point to the root of the build tree (needs GNU make).
   BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
   # make source path absolute
   source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

Quoted 5 lines

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

What tree is this going to go in via? I suggest the -trivial tree.

Quoted 6 lines
Quoted 2 lines

Applied (unchanged) to my trivial-patches branch.

Thank you Laurent.

I'll think about sending a followup patch with the changes proposed by Eric and I'll CC you if I do.

If you want to send a v3 of this patch to update it, I can wait.

Thanks,
Laurent

#10 lore raw
Quoted 65 lines · Laurent Vivier
Quoted 64 lines · Antonio Ospite
Quoted 63 lines · Laurent Vivier
Quoted 60 lines · Peter Maydell
Quoted 51 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
  Makefile  | 4 ++++
  configure | 6 ++++++

  2 files changed, 10 insertions(+)

+++ b/Makefile

Makefile +4 -0
@@ -1,5 +1,9 @@
   # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
   # Always point to the root of the build tree (needs GNU make).
   BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
   # make source path absolute
   source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

Quoted 5 lines

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

What tree is this going to go in via? I suggest the -trivial tree.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Applied (unchanged) to my trivial-patches branch.

Thank you Laurent.

I'll think about sending a followup patch with the changes proposed by Eric and I'll CC you if I do.

If you want to send a v3 of this patch to update it, I can wait.

That works too, I was waiting for the maintainers to decide what to do.

I'll try to send a v3 before Monday then.

Thanks,
Antonio

#11 lore raw
Quoted 71 lines · Antonio Ospite
Quoted 70 lines · Laurent Vivier
Quoted 69 lines · Antonio Ospite
Quoted 57 lines · Laurent Vivier
Quoted 56 lines · Peter Maydell
Quoted 55 lines · Eric Blake
Quoted 41 lines · Antonio Ospite

From: Antonio Ospite <[email protected]>

The configure script breaks when the qemu source directory is in a path containing white spaces, in particular the list of targets is not correctly generated when calling "./configure --help" because of how the default_target_list variable is built.

In addition to that, *building* qemu from a directory with spaces breaks some assumptions in the Makefiles, even if the original source path does not contain spaces like in the case of an out-of-tree build, or when symlinks are involved.

To avoid these issues, refuse to run the configure script and the Makefile if there are spaces or colons in the source path or the build path, taking as inspiration what the kbuild system in linux does.

---
  Makefile  | 4 ++++
  configure | 6 ++++++

  2 files changed, 10 insertions(+)

+++ b/Makefile

(quoted diff) +4 -0
@@ -1,5 +1,9 @@
   # Makefile for QEMU.
 
+ifneq ($(words $(subst :, ,$(CURDIR))), 1)
+  $(error main directory cannot contain spaces nor colons)
+endif
+
   # Always point to the root of the build tree (needs GNU make).
   BUILD_DIR=$(CURDIR)
 
configure +0 -0
index 9832cbca5c..f7ad4381bd 100755

configure ld_has() { · line 283

Quoted 5 lines
configure +2 -0
@@ -279,6 +279,12 @@ ld_has() {
   # make source path absolute
   source_path=$(cd "$(dirname -- "$0")"; pwd)
 
+if printf "%s\n" "$source_path" | grep -q "[[:space:]:]" ||
+  printf "%s\n" "$PWD" | grep -q "[[:space:]:]";

For less typing and fewer processes, you could shorten this to:

if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]";

but that's trivial enough for a maintainer to fold in if desired.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What tree is this going to go in via? I suggest the -trivial tree.

Applied (unchanged) to my trivial-patches branch.

Thank you Laurent.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I'll think about sending a followup patch with the changes proposed by Eric and I'll CC you if I do.

If you want to send a v3 of this patch to update it, I can wait.

That works too, I was waiting for the maintainers to decide what to do.

I'll try to send a v3 before Monday then.

OK, I will queue your v3 in the pull-request of the next week.

Thanks,
Laurent