llvm / llvm/llvm-project

[msan] scandirat is not intercepted

Open
#163,923 3 comments 0 reactions 0 assignees View on GitHub
compiler-rt:msan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
#define _GNU_SOURCE
#include
#include
#include
#include
#include

int filter(const struct dirent *d) {
return strlen(d->d_name) > 2;
}

int
main(void)
{
struct dirent **namelist;
int n;

n = scandirat(AT_FDCWD, ".", &namelist, filter, alphasort);
if (n == -1) {
perror("scandir");
exit(EXIT_FAILURE);
}

while (n--) {
printf("%s (%lu)\n", namelist[n]->d_name, strlen(namelist[n]->d_name));
free(namelist[n]);
}
free(namelist);

exit(EXIT_SUCCESS);
}
```

```
> clang -o /tmp/test test.c -fsanitize=memory -Wno-error
> /tmp/test
Uninitialized bytes in strlen at offset 0 inside [0x72d000000043, 2)
==374088==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55b4602f2d3c in filter (/tmp/test+0x109d3c)
#1 0x7f5179f5ee8a (/usr/lib64/libc.so.6+0xc7e8a)
#2 0x55b4602f2e48 in main (/tmp/test+0x109e48)
#3 0x7f5179ebd166 (/usr/lib64/libc.so.6+0x26166)
#4 0x7f5179ebd216 in __libc_start_main (/usr/lib64/libc.so.6+0x26216)
#5 0x55b460257170 in _start (/tmp/test+0x6e170)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/test+0x109d3c) in filter
Exiting
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the provided C reproducer with Clang and MemorySanitizer to confirm that scandirat triggers the uninitialized-value warning. No source file or test path is named in the issue, so locate the MemorySanitizer interception code for scandirat; done means the filter and subsequent directory-entry accesses run without this warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.