Forwarded from https://launchpad.net/bugs/392501
It seems that the actual size of "struct dirent" with LFS enabled is 280 bytes, but when defined for 32bit applications, the defined struct ends up at 276, and something (the kernel?) is still writing the remaining 4 bytes.
Built on 64bit: cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -o test-native test.c cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -m32 -o test-m32 test.c mkdir -p bug-dir touch bug-dir/111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ./test-native bug-dir sizeof(struct dirent): 280 ./test-m32 bug-dir sizeof(struct dirent): 276 *** stack smashing detected ***: ./test-m32 terminated
Built on 32bit: cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -o test-native test.c cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -m32 -o test-m32 test.c mkdir -p bug-dir touch bug-dir/111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ./test-native bug-dir sizeof(struct dirent): 276 *** stack smashing detected ***: ./test-native terminated
/// test.c #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <inttypes.h>
void func(const char*path) { struct dirent entry; struct dirent *result = NULL; int ret;
DIR *dir = opendir(path); if(!dir) abort(); printf("sizeof(struct dirent): %" PRIuFAST32 "\n", sizeof(entry)); while (!(ret = readdir_r(dir, &entry, &result)) && result) {} }
int main(int argc, const char** argv) { if(argc < 2) abort(); func(argv[1]); return 0; }
Forwarded from https:/ /launchpad. net/bugs/ 392501
It seems that the actual size of "struct dirent" with LFS enabled is 280 bytes,
but when defined for 32bit applications, the defined struct ends up at 276, and
something (the kernel?) is still writing the remaining 4 bytes.
Built on 64bit: OFFSET_ BITS=64 OFFSET_ BITS=64 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111
cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_
-o test-native test.c
cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_
-m32 -o test-m32 test.c
mkdir -p bug-dir
touch
bug-dir/
./test-native bug-dir
sizeof(struct dirent): 280
./test-m32 bug-dir
sizeof(struct dirent): 276
*** stack smashing detected ***: ./test-m32 terminated
Built on 32bit: OFFSET_ BITS=64 OFFSET_ BITS=64 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111 111111111111111
cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_
-o test-native test.c
cc -Wall -Werror -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_
-m32 -o test-m32 test.c
mkdir -p bug-dir
touch
bug-dir/
./test-native bug-dir
sizeof(struct dirent): 276
*** stack smashing detected ***: ./test-native terminated
/// test.c
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <inttypes.h>
void func(const char*path) {
struct dirent entry;
struct dirent *result = NULL;
int ret;
DIR *dir = opendir(path); "sizeof( struct dirent): %" PRIuFAST32 "\n", sizeof(entry));
if(!dir) abort();
printf(
while (!(ret = readdir_r(dir, &entry, &result)) && result) {}
}
int main(int argc, const char** argv) {
if(argc < 2) abort();
func(argv[1]);
return 0;
}