On 06/02/2009 01:33 PM, Roman Rakus wrote:
When you are sourcing bash script, which contains \0 character, bash thinks it is end of file. I have investigated, that `source' loads entire file into memory as string. Then \0 is end of this string. One of the possible solution is to left out all \0 characters. This doesn't seem to be perfect. Another possible solution is to count size of the file and then compare the size with actual string parsing.
Maybe other solutions...

Which solution should be the best?
RR


This patch will delete all `\0' characters which are not at the end of sourced file.
RR
diff -up bash-3.2/builtins/evalfile.c.nullchar bash-3.2/builtins/evalfile.c
--- bash-3.2/builtins/evalfile.c.nullchar       2006-07-28 03:41:43.000000000 
+0200
+++ bash-3.2/builtins/evalfile.c        2009-06-01 13:00:31.000000000 +0200
@@ -77,7 +77,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;
   char *string;
   struct stat finfo;
   size_t file_size;
@@ -174,7 +174,15 @@ file_error_and_exit:
       (*errfunc) ("%s: cannot execute binary file", filename);
       return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
     }
-
+  while (i < result)
+    {
+      if (string[i] == '\0')
+        {
+          memmove(&string[i], &string[i+1], result - i);
+          --result;
+        }
+      ++i;
+    }
   if (flags & FEVAL_UNWINDPROT)
     {
       begin_unwind_frame ("_evalfile");

Reply via email to