sanity.bbclass: check for validity of TMPDIR
v3 cover sanity.bbclass: check for validity of TMPDIR
Changes since V2:
1. Check for trailing slashes as well.
The following changes since commit e93a345fae7c21652547bec501fcb1f3b6c6427d:
sstate: add do_package to the noexec list in setscene_depvalid (2014-01-07 13:58:32 +0000)
are available in the git repository at:
git://git.pokylinux.org/poky-contrib ChenQi/TMPDIR
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/TMPDIR
Chen Qi (1):
sanity.bbclass: check for validity of TMPDIR
meta/classes/sanity.bbclass | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v3 1/1 sanity.bbclass: check for validity of TMPDIR
TMPDIR must be an absolute path, otherwise, the build will fail. Special characters and trailing slashes in TMPDIR will also cause build failures.
This patch enables checking for the validity of TMPDIR.
The logic in sanity.bbclass has also been changed a little bit. For now, we only create the directory hierarch for TMPDIR if TMPDIR is valid. And also, we only handle ABI version change only if the TMPDIR directory hierarchy has been created.
[YOCTO #5690]
--- meta/classes/sanity.bbclass | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
meta/classes/sanity.bbclass +23 -4
@@ -666,6 +666,16 @@ def check_sanity_everybuild(status, d): if oeroot.find(' ') != -1: status.addresult("Error, you have a space in your COREBASE directory path. Please move the installation to a directory which doesn't include a space since autotools doesn't support this.") + # Function to check if TMPDIR contains invalid characters, and check if it is an absolute path + def is_tmpdir_valid(path): + import re + valid_tmpdir_regexp = "^/[a-zA-Z0-9\-_/.~]*[a-zA-Z0-9\-_.~]$" + valid_pattern = re.compile(valid_tmpdir_regexp) + if valid_pattern.match(path): + return True + else: + return False + # Check that TMPDIR hasn't changed location since the last time we were run tmpdir = d.getVar('TMPDIR', True) checkfile = os.path.join(tmpdir, "saved_tmpdir")
@@ -674,10 +684,16 @@ def check_sanity_everybuild(status, d): saved_tmpdir = f.read().strip() if (saved_tmpdir != tmpdir): status.addresult("Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir) + if not is_tmpdir_valid(tmpdir): + status.addresult("Error, you an invalid TMPDIR path. The TMPDIR must be an absolute path with no special characters and no trailing slashes.") else: - bb.utils.mkdirhier(tmpdir) - with open(checkfile, "w") as f: - f.write(tmpdir) + if not is_tmpdir_valid(tmpdir): + status.addresult("Error, you an invalid TMPDIR path. The TMPDIR must be an absolute path with no special characters and no trailing slashes.") + else: + # Make directory hierarchy for TMPDIR only if TMPDIR is valid + bb.utils.mkdirhier(tmpdir) + with open(checkfile, "w") as f: + f.write(tmpdir) def check_sanity(sanity_data): import subprocess
@@ -729,7 +745,10 @@ def check_sanity(sanity_data): f.write("TMPDIR %s\n" % tmpdir) f.write("SSTATE_DIR %s\n" % sstate_dir) - sanity_handle_abichanges(status, sanity_data) + # Handle ABI version change only if TMPDIR hierarchy has been created + saved_tmpdir = os.path.join(tmpdir, "saved_tmpdir") + if os.path.exists(saved_tmpdir): + sanity_handle_abichanges(status, sanity_data) if status.messages != "": raise_sanity_error(sanity_data.expand(status.messages), sanity_data, status.network_error)
Signature · 1 line
1.7.9.5
ping
Any comment on this one?
//Chen Qi
Quoted 71 lines · Chen Qi
TMPDIR must be an absolute path, otherwise, the build will fail. Special characters and trailing slashes in TMPDIR will also cause build failures.
This patch enables checking for the validity of TMPDIR.
The logic in sanity.bbclass has also been changed a little bit. For now, we only create the directory hierarch for TMPDIR if TMPDIR is valid. And also, we only handle ABI version change only if the TMPDIR directory hierarchy has been created.
[YOCTO #5690]
Signed-off-by Chen Qi <[email protected]>--- meta/classes/sanity.bbclass | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)meta/classes/sanity.bbclass +23
-4@@ -666,6 +666,16 @@ def check_sanity_everybuild(status, d): if oeroot.find(' ') != -1: status.addresult("Error, you have a space in your COREBASE directory path. Please move the installation to a directory which doesn't include a space since autotools doesn't support this.") + # Function to check if TMPDIR contains invalid characters, and check if it is an absolute path + def is_tmpdir_valid(path): + import re + valid_tmpdir_regexp = "^/[a-zA-Z0-9\-_/.~]*[a-zA-Z0-9\-_.~]$" + valid_pattern = re.compile(valid_tmpdir_regexp) + if valid_pattern.match(path): + return True + else: + return False + # Check that TMPDIR hasn't changed location since the last time we were run tmpdir = d.getVar('TMPDIR', True) checkfile = os.path.join(tmpdir, "saved_tmpdir")@@ -674,10 +684,16 @@ def check_sanity_everybuild(status, d): saved_tmpdir = f.read().strip() if (saved_tmpdir != tmpdir): status.addresult("Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir) + if not is_tmpdir_valid(tmpdir): + status.addresult("Error, you an invalid TMPDIR path. The TMPDIR must be an absolute path with no special characters and no trailing slashes.") else: - bb.utils.mkdirhier(tmpdir) - with open(checkfile, "w") as f: - f.write(tmpdir) + if not is_tmpdir_valid(tmpdir): + status.addresult("Error, you an invalid TMPDIR path. The TMPDIR must be an absolute path with no special characters and no trailing slashes.") + else: + # Make directory hierarchy for TMPDIR only if TMPDIR is valid + bb.utils.mkdirhier(tmpdir) + with open(checkfile, "w") as f: + f.write(tmpdir) def check_sanity(sanity_data): import subprocess@@ -729,7 +745,10 @@ def check_sanity(sanity_data): f.write("TMPDIR %s\n" % tmpdir) f.write("SSTATE_DIR %s\n" % sstate_dir) - sanity_handle_abichanges(status, sanity_data) + # Handle ABI version change only if TMPDIR hierarchy has been created + saved_tmpdir = os.path.join(tmpdir, "saved_tmpdir") + if os.path.exists(saved_tmpdir): + sanity_handle_abichanges(status, sanity_data) if status.messages != "": raise_sanity_error(sanity_data.expand(status.messages), sanity_data, status.network_error)