Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

src/freon.c mishandles 3rd arg to open functions (mode) #3140

@vapier

Description

@vapier

the open signature is:
int open(const char *pathname, int flags, ...);

and mode is only passed in for certain flags (O_CREAT and O_TMPFILE), so trying to extract it otherwise is undefined behavior. you might get garbage, or you might crash.

freon.c assumes it's always passed in:

int open(const char *pathname, int flags, ...) {
    if (!orig_open) preload_init();

    va_list argp;
    va_start(argp, flags);
    mode_t mode = va_arg(argp, mode_t);
    va_end(argp);

same for open64.

you can do something instead like:

int open(const char *pathname, int flags, ...) {
    if (!orig_open) preload_init();

    mode_t mode = 0;
    va_list argp;
    va_start(argp, flags);
    if (flags & (O_CREAT | O_TMPFILE))
        mode = va_arg(argp, mode_t);
    va_end(argp);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions