Bug 11053

Summary: insane.bbclass: Verify shebang line length valid
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Juro Bystricky <juro.bystricky>
Component: coreAssignee: Paulo Neves <ptsneves>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: Medium CC: dorindabassey, markus.lehtonen, meta.mr.watcher, meta.watcher, ptsneves, randy.macleod, richard.purdie, sakib.sajal
Version: 2.3   
Target Milestone: Future   
Hardware: x86   
OS: Multiple   
Whiteboard: NEWCOMER
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Juro Bystricky 2017-02-14 17:44:22 UTC
The valid "shebang" line length is determined by linux kernel, in particular
BINPRM_BUF_SIZE in include/uapi/linux/binfmts.h:

#define BINPRM_BUF_SIZE 128


Which means that any shebang line should be shorter.
If it is not, we get all kinds of permission errors trying to run the script.
So it would make sense for sanity checks to verify the line length.
Comment 1 Markus Lehtonen 2017-02-23 12:19:39 UTC
Could you elaborate a bit more, what scripts are you thinking of? Any scripts bitbake runs, anything that gets installed into the image or something else?

In which kind of situation have you hit this problem? If shebang is too long your should get "bad interpreter" error, not a permission error, right?
Comment 2 Markus Lehtonen 2017-02-23 12:23:14 UTC
I should've read the bug heading a bit better. Answering to myself: you're obviously referring to files getting installed into the image (or packaged) :)
Comment 3 Juro Bystricky 2017-02-24 17:13:12 UTC
(In reply to comment #2)
> I should've read the bug heading a bit better. Answering to myself: you're
> obviously referring to files getting installed into the image (or packaged)
> :)

I ran into this when trying to use native easy_install. The shebang line was:

#!/data/master-multi/poky/build-pip3-native/tmp/work/x86_64-linux/python3-setuptools-native/32.1.1-r0/recipe-sysroot-native/usr/bin/env python3

which "looks" correct as the path exists, but too long. (The recipe needs to be fixed, but that is a different issue). This did generate permission errors due to bad interpreter. (That was a bit confusing, as the error did not say anything about bad interpreter) . 
So if sanity caught this, it would have saved me a lot of head scratching.
Comment 4 Markus Lehtonen 2017-05-16 08:53:10 UTC
Moving this now to 2.4.

I think we should add a new test scanning all files found in the recipe recipe-sysroot-native.

In contrast to my previous comment, it should not be necessary to scan the files being installed into the target. There, the paths should always be reasonably short.
Comment 5 Dorinda 2020-10-22 10:09:34 UTC
hi,
would it be wise to add a task function in the insane.bbclass that would perform the sanity check for long shebang lines like this below:

addtask do_shebangline_check before do_fetch
python do_shebangline_check(){
   #am still trying to figure this part out
   #determine if it is a shebang line
   if IFS= LC_ALL=C read -rN2 -d '' shebang < file && [ "$shebang" = '#!' ];
   then
      str = $0
      #limit the shebang line length to 80 chars
      if ${#str} > 80
         echo "shebang length is too long install into a directory with shorter path"
      fi
   fi
}
#and export the function 
EXPORT_FUNCTIONS do_shebangline_check


some guide will be much appreciated

thanks,
Dorinda
Comment 6 Paulo Neves 2022-06-06 16:09:09 UTC
@Dorinda, sorry for the late answer. Your proposal was in the end not required due to the check already existing for packages, needing only adaptations to make it also run on the staging task to fix this bug report. It can be found here [1]. It is a bit more optimized than your proposal, and does not require an extra task.

@Markus the files for the target are already scanned by [1] when packaging.

@all I submitted the following attempt at fixing it, including test:
https://lists.openembedded.org/g/openembedded-core/message/166651
https://lists.openembedded.org/g/openembedded-core/message/166652

[1] https://git.yoctoproject.org/poky/tree/meta/classes/insane.bbclass#n78
Comment 7 Paulo Neves 2022-06-29 11:00:18 UTC
in master next