Bug 32106

Summary: Scripts with #!/interpreter paths longer than 64 bytes don't work.
Product: Base System Reporter: Magnus Backstrom <b>
Component: kernAssignee: John W. De Boskey <jwd>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.4-STABLE   
Hardware: Any   
OS: Any   

Description Magnus Backstrom 2001-11-19 15:50:01 UTC
If an interpreter pathname is longer than about 64 characters, i.e.
#!/you/have/a/slightly/longer/than/usual/path/to/your/interpreter,
/bin/sh gets used instead and your script may break.

Fix: 

Change line 39 of /usr/src/sys/sys/imgact.h from
#define MAXSHELLCMDLEN  64
to something more sensible, e g
#define MAXSHELLCMDLEN  512
This doesn't seem to break anything.
How-To-Repeat: x> mkdir -p /tmp/this/is/a/slightly/too/long/path/to/the/interpreter
x> ln -s /usr/bin/awk \
    /tmp/this/is/a/slightly/too/long/path/to/the/interpreter
x> cat > /tmp/test.awk
#!/tmp/this/is/a/slightly/too/long/path/to/the/interpreter/awk -f
{ 1 }
x> chmod +x /tmp/test.awk 
x> /tmp/test.awk 
{: Command not found.
x>
Comment 1 John W. De Boskey freebsd_committer freebsd_triage 2001-11-26 02:42:09 UTC
Responsible Changed
From-To: freebsd-bugs->jwd

I've looked into the problem and will followup.
Comment 2 John W. De Boskey freebsd_committer freebsd_triage 2001-11-28 03:27:13 UTC
State Changed
From-To: open->feedback

Fix committed for secondary /bin/sh execution.  
Increased MAXSHELLCMDLEN to 128. Waiting on feedback 
from submitter.
Comment 3 John W. De Boskey freebsd_committer freebsd_triage 2001-11-29 02:31:16 UTC
State Changed
From-To: feedback->closed

Received positive feedback from Magnus.