Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vapier opened this issue Mar 10, 2017 · 0 comments · May be fixed by #3273
Closed

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

vapier opened this issue Mar 10, 2017 · 0 comments · May be fixed by #3273

Comments

@vapier
Copy link

vapier commented Mar 10, 2017

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants