[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#563882: git-core FTBFS on ia64: t1001-read-tree-m-2way.sh test fails

severity 563882 important
retitle 563882 ia64: memchr overshots

On Tue, Jan 26, 2010 at 01:48:34PM -0600, Jonathan Nieder wrote:
> severity 563882 critical

Please explain. git is neither unrelated to glibc nor does this cause
serious data loss.

> That is, it maps the file into memory and looks for null bytes.

No, the kernel always maps complete pages, so this maps several null

> Then this program would lie to you and say “M.out is binary”

The test program does not properly show what is going on.

The following program shows the cause:

| #include <sys/stat.h>
| #include <sys/mman.h>
| #include <fcntl.h>
| int main(int argc, const char * const argv[])
| { 
|   struct stat st;
|   lstat(argv[1], &st);
|   int fd = open(argv[1], O_RDONLY);
|   void *data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|   void *t = memchr(data, 0, st.st_size);
|   printf("ptr: %p, ret: %p, len: 0x%zx\n", data, t, st.st_size);
|   return 0;
| }

Example output:
| % ./test /etc/passwd
| ptr: 0x2000000000050000, ret: 0x200000000005040e, len: 0x40e

The found location is already after the buffer. memchr is AFAIK expanded
by gcc.


Where there's no emotion, there's no motive for violence.
		-- Spock, "Dagger of the Mind", stardate 2715.1

Reply to: