Skip site navigation (1)Skip section navigation (2)
Date:      10 Dec 2000 06:09:12 -0000
From:      mwm@mired.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/23410: [PATCH] FreeBSD throws away information on failed #! execs; this recreates it
Message-ID:  <20001210060912.3812.qmail@guru.mired.org>
Resent-Message-ID: <200012100610.eBA6A0353572@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         23410
>Category:       ports
>Synopsis:       [PATCH] FreeBSD throws away information on failed #! execs; this recreates it
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 09 22:10: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 #0: Sun Dec 3 05:30:23 CST 2000 mwm@guru.mired.org:/usr/obj/sharetmp/src/sys/GURU i386


>Description:

See http://www.freebsd.org/cgi/query-pr.cgi?pr=22755 for a detailed
description of the problem, and why this is being fixed in ports.

>How-To-Repeat:

See http://www.freebsd.org/cgi/query-pr.cgi?pr=22755 for a detailed
description of the problem, and why this is being fixed in ports.

>Fix:

Add the following patch to the patches for the shell/bash2 port. That
at least fixes the problem for bash2. I'm assuming alfred won't mind
helping users of others shells fix theirs, as he advocates this
solution.

--- execute_cmd.c.orig	Tue Jan 25 10:29:11 2000
+++ execute_cmd.c	Sat Dec  9 23:59:00 2000
@@ -3311,11 +3311,30 @@
 {
   struct stat finfo;
   int larray, i, fd;
+  unsigned char sample[80];
+  int sample_len;
 
   SETOSTYPE (0);		/* Some systems use for USG/POSIX semantics */
   execve (command, args, env);
   SETOSTYPE (1);
 
+  fd = open (command, O_RDONLY);
+  if (fd >= 0)
+    {
+      sample_len = read (fd, (char *)sample, 80);
+      close (fd);
+    }
+  else
+    sample_len = 0;
+
+#if defined(HAVE_HASH_BANG_EXEC)
+  if (sample_len > 2 && sample[0] == '#' && sample[1] == '!'
+      && !access(command, X_OK | R_OK)) {
+    internal_error("%s: bad interpreter", command);
+    return EX_NOEXEC;
+  }
+#endif
+
   /* If we get to this point, then start checking out the file.
      Maybe it is something we can hack ourselves. */
   if (errno != ENOEXEC)
@@ -3336,38 +3355,30 @@
      systems.  Otherwise, check to see if it is a binary file by seeing
      if the first line (or up to 80 characters) are in the ASCII set.
      Execute the contents as shell commands. */
-  fd = open (command, O_RDONLY);
-  if (fd >= 0)
-    {
-      unsigned char sample[80];
-      int sample_len;
 
-      sample_len = read (fd, (char *)sample, 80);
-      close (fd);
-
-      if (sample_len == 0)
-	return (EXECUTION_SUCCESS);
+ if (sample_len == 0)
+   return (EXECUTION_SUCCESS);
 
-      /* Is this supposed to be an executable script?
-	 If so, the format of the line is "#! interpreter [argument]".
-	 A single argument is allowed.  The BSD kernel restricts
-	 the length of the entire line to 32 characters (32 bytes
-	 being the size of the BSD exec header), but we allow 80
-	 characters. */
-      if (sample_len > 0)
-	{
+ /* Is this supposed to be an executable script?
+    If so, the format of the line is "#! interpreter [argument]".
+    A single argument is allowed.  The BSD kernel restricts
+    the length of the entire line to 32 characters (32 bytes
+    being the size of the BSD exec header), but we allow 80
+    characters. */
+ if (sample_len > 0)
+   {
 #if !defined (HAVE_HASH_BANG_EXEC)
-	  if (sample[0] == '#' && sample[1] == '!')
-	    return (execute_shell_script (sample, sample_len, command, args, env));
-	  else
+     if (sample[0] == '#' && sample[1] == '!')
+       return (execute_shell_script (sample, sample_len, command, args, env));
+     else
 #endif
-	  if (check_binary_file (sample, sample_len))
-	    {
-	      internal_error ("%s: cannot execute binary file", command);
-	      return (EX_BINARY_FILE);
-	    }
-	}
-    }
+       if (check_binary_file (sample, sample_len))
+	 {
+	   internal_error ("%s: cannot execute binary file", command);
+	   return (EX_BINARY_FILE);
+	 }
+   }
+
 
   initialize_subshell ();
 



>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001210060912.3812.qmail>