@@ -1,11 +1,11 @@
-SUMMARY = "Check that shebang does not exceed 128 characters"
+SUMMARY = "Check that shebang does not exceed 256 characters"
LICENSE = "CLOSED"
INHIBIT_DEFAULT_DEPS = "1"
EXCLUDE_FROM_WORLD = "1"
do_install() {
install -d ${D}${bindir}
- echo '#!BiM3cnVd1Amtv6PG+FynrQiVMbZnX5ELgF21q3EkuB+44JEGWtq8TvBJ7EGidfVs3eR3wVOUbLnjYDlKUWcm7YC/ute7f+KDHbwxziRUSUBZAUqgjiQdfQ0HnxajI0ozbM863E9JV9k13yZKYfh9/zR77Y6Dl4Dd3zOWS75LSpkAXV' > ${D}${bindir}/max-shebang
+ echo '#!4Shfcy9Ej8gPKDGNkyhmtxrwPinmpZQ1pCS3snbdqlNx7YfmTpHkeJakCMaDnQXx4c4TmtyJpGBn5F7IO1FShYG9EwtALDOsRKEDOJKRj2L7hW92wZTzlqx4mMqREqNa7Hrwql4DYVv8vmEMhIwvtHO3UaVpgvLY9Y3HhfopUVUMZJi5Xs9KKkRisrM0HBePG67tbeWL9ZstNuPKH1ikyeNB7PprwLrsjZ6EngCrhFTfYzRSuXhdrQQBBsLZBRDsy5QE' > ${D}${bindir}/max-shebang
chmod 755 ${D}${bindir}/max-shebang
}
@@ -83,25 +83,22 @@ QAPATHTEST[shebang-size] = "package_qa_check_shebang_size"
def package_qa_check_shebang_size(path, name, d, elf):
global cpath
+ # From kernel 5.1 onwards (specifically linux 6eb3c3d0a52dc ("exec: increase
+ # BINPRM_BUF_SIZE to 256")) the shebang buffer was increased from 128 bytes
+ # to 256 bytes.
+ BINPRM_BUF_SIZE = 256
+
if elf or cpath.islink(path) or not cpath.isfile(path):
return
try:
with open(path, 'rb') as f:
- stanza = f.readline(130)
+ stanza = f.readline(BINPRM_BUF_SIZE * 2)
+ if stanza.startswith(b'#!') and len(stanza) > BINPRM_BUF_SIZE:
+ oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is %d" % (name, package_qa_clean_path(path, d, name), BINPRM_BUF_SIZE), d)
+ return
except IOError:
- return
-
- if stanza.startswith(b'#!'):
- try:
- stanza.decode("utf-8")
- except UnicodeDecodeError:
- #If it is not a text file, it is not a script
- return
-
- if len(stanza) > 129:
- oe.qa.handle_error("shebang-size", "%s: %s maximum shebang size exceeded, the maximum size is 128." % (name, package_qa_clean_path(path, d, name)), d)
- return
+ pass
QAPATHTEST[libexec] = "package_qa_check_libexec"
def package_qa_check_libexec(path,name, d, elf):
@@ -44,9 +44,8 @@ TESTSTRING:pn-sysroot-test-arch2 = "%s"
Expected: Fail when a shebang bigger than the max shebang-size is reached.
Author: Paulo Neves <ptsneves@gmail.com>
"""
- expected = "maximum shebang size exceeded, the maximum size is 128. [shebang-size]"
res = bitbake("sysroot-shebang-test-native -c populate_sysroot", ignore_status=True)
- self.assertTrue(expected in res.output, msg=res.output)
+ self.assertTrue("[shebang-size]" in res.output, msg=res.output)
self.assertTrue(res.status != 0)
def test_sysroot_la(self):
Since Linux 5.1 the shebang buffer has been 256 bytes[1], so update the check to match. Also rewrite the test, create a variable for the magic number (that has the same name as the kernel #define), read double that so we either have a full line, or definitely are over the buffer, don't pointlessly try to decode the bytes as UTF-8, and consolidate the test logic to entirely inside the try block. Also update the tests: sysroot-shebang-test needs updating to write a longer shebang, and generalise the test case so that the string being searched for isn't so specific. [1] linux 6eb3c3d0a52dc ("exec: increase BINPRM_BUF_SIZE to 256") Signed-off-by: Ross Burton <ross.burton@arm.com> --- .../sysroot-test/sysroot-shebang-test_1.0.bb | 4 ++-- meta/classes-global/insane.bbclass | 23 ++++++++----------- meta/lib/oeqa/selftest/cases/sysroot.py | 3 +-- 3 files changed, 13 insertions(+), 17 deletions(-)