source(builtin) and read(2)

2007-03-23 Thread hooanon05
Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H  -I.  -I../bash -I../bash/include 
-I../bash/lib  -g -O2
uname output: Linux jroun 2.6.8-16sarge5jroun #1 Tue Nov 21 16:22:30 JST 2006 
i686 GNU/Linux
Machine Type: i386-pc-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
The source builtin command reads the given file after getting its size
by fstat(2). But bash doen't check the read bytes which is a return
value of read(2).

builtins/evalfile.c
_evalfile()
{
  fd = open (filename, O_RDONLY);
  fstat (fd, &finfo);
  file_size = (size_t)finfo.st_size;
  string = (char *)xmalloc (1 + file_size);
  result = read (fd, string, file_size);
  string[result] = '\0';
;;;
}
(I checked bash-3.0 too)

When the file size is very large or the filesystem is poor, the read(2)
systemcall may not read all of the file. In this case, the return value
will be shorter than the requested bytes.
Should bash read the remaining bytes, or is it a problem of filesystem?
I think that read(2) systemcall doesn't guarantee the requested bytes
are all retrived.
Does it guaranteed that the regular file is read all?

Thank you very much for your good work.


Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]

Fix:
[Description of how to fix the problem.  If you don't know a
fix for the problem, don't include this section.]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: source(builtin) and read(2)

2007-03-26 Thread hooanon05

Andreas Schwab:
> > When the file size is very large or the filesystem is poor, the read(2)
> > systemcall may not read all of the file. In this case, the return value
> > will be shorter than the requested bytes.
> 
> Even worse, if read returns -1 then this writes beyond array bounds.
> Also, file_size is size_t, but result is only int.

Thank you for your reply.
Although I think these are rare cases, they can be a problem.
- a file larger than MAX_INT.
- read(2) error (returns -1)
  + signal?
  + another process issues chmod(2) and makes the file unreadable,
 between fstat(2) and read(2) in _evalfile().
  + or anything else.
- read(2) succeeds, but the return value is shorter than the requested
  bytes.

Do you have a plan to fix it?

Junjiro Okajima


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash