From owner-freebsd-bugs Fri Nov 10 12:20:10 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 471BA37B4C5 for ; Fri, 10 Nov 2000 12:20:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id MAA01506; Fri, 10 Nov 2000 12:20:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from guru.mired.org (okc-27-149-77.mmcable.com [24.27.149.77]) by hub.freebsd.org (Postfix) with SMTP id 5001F37B479 for ; Fri, 10 Nov 2000 12:15:52 -0800 (PST) Received: (qmail 45034 invoked by uid 100); 10 Nov 2000 20:15:44 -0000 Message-Id: <20001110201544.45033.qmail@guru.mired.org> Date: 10 Nov 2000 20:15:44 -0000 From: mwm@mired.org Reply-To: mwm@mired.org To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: kern/22755: Errors reports about the interpreter on scripts are bogus Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 22755 >Category: kern >Synopsis: Errors reports about the interpreter on scripts are bogus >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Nov 10 12:20:00 PST 2000 >Closed-Date: >Last-Modified: >Originator: Mike Meyer >Release: FreeBSD 5.0-CURRENT i386 >Organization: Meyer Consulting >Environment: System: FreeBSD guru.mired.org 5.0-CURRENT FreeBSD 5.0-CURRENT #22: Tue Nov 7 22:31:36 CST 2000 mwm@guru.mired.org:/sharetmp/src/sys/compile/GURU i386 libc is involved. >Description: If an error is found with the interpreter in an executable script, the error with the interpreter is reported to the shell, which then reports the problem to the user as belonging to the script. So the user winds up seeing "/usr/local/bin/script: No such file or directory" or "/usr/local/bin/script: Permission denied" and so on, even though "which script" reports /usr/local/bin/script, and the permission are clearly correct, and in general the problem isn't with the script. These error messages are at best misleading, and at worst wrong. This is a kernel problem, as its error indication is wrong. There's no way for the shell to do anything other than what it does. >How-To-Repeat: Create a mode 755 file on your path with first lines like: #!/dev/null/notthere or #!/etc/fstab or #!/usr/bin/shar and notice that you get messages that finger the script, but apply to the file you listed in the executable. >Fix: The attached patch solves the problem. The first file patched (kern_exec.c) fixes the problem proper. Any errors found with the #! line or when trying to execute an interpreter are changed to EINVALINTERP. If the problem occurs before the shell image activer gets started, the actual error is reported, and is probably correct (i.e. - if the permissions on the script are wrong, it gets reported as such). I couldn't find an error I thought was appropriate. The second two files patched (errlst.c & errno.h) add the EINVALINTERP error. If you think an existing error is a good match, change EINVALINTERP in the first file patched to that error, and skip the second two files. In fact, I first tested the patch by using EFTYPE. The last file patched (imgact_shell.c) is just cleanup. It currently returns ENOEXEC if there are problems, which the first patch will change to EINVALINTERP (or whatever), which seems cleaner. Leaving it off won't change the behavior of the system after the first patch is applied. If the new error number is used, shells that statically link libc will just report "error 87" or some such until they are relinked. --- sys/kern/kern_exec.c-orig Fri Nov 10 03:06:47 2000 +++ sys/kern/kern_exec.c Fri Nov 10 04:09:03 2000 @@ -382,6 +382,7 @@ /* NOT REACHED */ return(0); } else { + if (error && imgp->interpreted) error = EINVALINTERP; return(error); } } --- lib/libc/gen/errlst.c-orig Fri Nov 10 03:15:18 2000 +++ lib/libc/gen/errlst.c Fri Nov 10 03:15:46 2000 @@ -143,6 +143,7 @@ "Value too large to be stored in data type", /* 84 - EOVERFLOW */ "Operation canceled", /* 85 - ECANCELED */ "Illegal byte sequence", /* 86 - EILSEQ */ + "Invalid interpreter", /* 87 - EINVALINTERP */ }; int errno; const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); --- sys/sys/errno.h-orig Fri Nov 10 03:12:06 2000 +++ sys/sys/errno.h Fri Nov 10 03:12:47 2000 @@ -167,7 +167,8 @@ #define EOVERFLOW 84 /* Value too large to be stored in data type */ #define ECANCELED 85 /* Operation canceled */ #define EILSEQ 86 /* Illegal byte sequence */ -#define ELAST 86 /* Must be equal largest errno */ +#define EINVALINTERP 87 /* Invalid Interpreter */ +#define ELAST 87 /* Must be equal largest errno */ #endif /* _POSIX_SOURCE */ --- imgact_shell.c-orig Wed Apr 26 15:58:39 2000 +++ imgact_shell.c Fri Nov 10 03:29:11 2000 @@ -60,7 +60,7 @@ * script. :-) */ if (imgp->interpreted) - return(ENOEXEC); + return(EINVALINTERP); imgp->interpreted = 1; @@ -74,7 +74,7 @@ */ for (ihp = &image_header[2]; *ihp != '\n' && *ihp != '#'; ++ihp) { if (ihp >= &image_header[MAXSHELLCMDLEN]) - return(ENOEXEC); + return(EINVALINTERP); } line_endp = ihp; @@ -92,7 +92,7 @@ /* Disallow a null interpreter filename */ if (*imgp->interpreter_name == '\0') - return(ENOEXEC); + return(EINVALINTERP); /* reset for another pass */ ihp = &image_header[2]; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message