ggreer/the_silver_searcher — pull request #219 by enukane (2013-05-24 06:03:46+00:00)
Title: fix SIGSSEGV in mempy called from ag_scandir

In some cases, or perhaps depending on its OS, ag gets SEGV as below. In my case , this happens on OpenBSD 5.2

It seems like copying whole dirent with memcpy is not good.
Actual dirent from readdir could be shorter than sizeof(struct dirent) and touching whole structure can sometimes cause SEGV.
The patch uses d_reclen for the length, which is passed as "length of the record".

% ~/Sources/the_silver_searcher/ag "boot processor"
arch/amd64/amd64/cpu.c
221: * the local APIC on the boot processor has been mapped.
375: printf("apid %d (boot processor)\n", caa->cpu_number);
zsh: segmentation fault (core dumped) ~/Sources/the_silver_searcher/ag "boot processor"