Skip to content

[MSan] Memory Sanitizer false positive detects use of uninitialized variable with timespec_get #156767

@yamam

Description

@yamam

Referencing the time obtained with timespec_get results in a false positive detection of an uninitialized variable by MemorySanitizer.
In contrast, the time obtained with clock_gettime works correctly without issues.

Environment
Ubuntu 24.04.3
Clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Reproduction steps
Compile and run the following program with the command below:

#include <time.h>
int main(void) {
    struct timespec tv1, tv2;
    clock_gettime(CLOCK_MONOTONIC, &tv1); /* OK */
    if(tv1.tv_sec == 0) { return 0; }
    timespec_get(&tv2, TIME_UTC); /* NG */
    if(tv2.tv_sec == 0) { return 0; }
    return 1;
}
clang -fsanitize=memory -fsanitize-memory-track-origins -fPIE -fno-common test.c && ./a.out

Error message

==3898142==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55555561e57e in main (/tmp/a.out+0xca57e) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)
    #1 0x7ffff7c2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #2 0x7ffff7c2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
    #3 0x555555586304 in _start (/tmp/a.out+0x32304) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)

  Uninitialized value was created by an allocation of 'tv2' in the stack frame
    #0 0x55555561e435 in main (/tmp/a.out+0xca435) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/tmp/a.out+0xca57e) (BuildId: 5c4a39751b635480181bc84a227f82ab740f925c) in main
Exiting

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions