]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - builtins/evalfile.c
Bash-4.1 distribution source
[thirdparty/bash.git] / builtins / evalfile.c
index 55b5cb786b7fccd4d39cbc188ea6c81469fbceee..972d03932989600fa3f06cd8db57b011d67165fc 100644 (file)
@@ -81,7 +81,7 @@ _evalfile (filename, flags)
 {
   volatile int old_interactive;
   procenv_t old_return_catch;
-  int return_val, fd, result, pflags;
+  int return_val, fd, result, pflags, i, nnull;
   ssize_t nr;                  /* return value from read(2) */
   char *string;
   struct stat finfo;
@@ -186,6 +186,26 @@ file_error_and_exit:
       return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
     }
 
+  i = strlen (string);
+  if (i < nr)
+    {
+      for (nnull = i = 0; i < nr; i++)
+       if (string[i] == '\0')
+          {
+           memmove (string+i, string+i+1, nr - i);
+           nr--;
+           /* Even if the `check binary' flag is not set, we want to avoid
+              sourcing files with more than 256 null characters -- that
+              probably indicates a binary file. */
+           if ((flags & FEVAL_BUILTIN) && ++nnull > 256)
+             {
+               free (string);
+               (*errfunc) (_("%s: cannot execute binary file"), filename);
+               return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
+             }
+          }
+    }
+
   if (flags & FEVAL_UNWINDPROT)
     {
       begin_unwind_frame ("_evalfile");