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

unix: don't convert stat buffer when syscall fails #921

Merged
merged 1 commit into from Jun 22, 2016

Conversation

bnoordhuis
Copy link
Member

Don't call uv__to_stat() when the stat/fstat/lstat system call fails;
the stack-allocated buffer contains only garbage in that case.

Not a very serious bug it's technically undefined behavior and it made
valgrind squawk.

Introduced in commit 499c797 ("unix, windows: nanosecond resolution
for uv_fs_[fl]stat").

Alternatively, we could memset(pbuf, 0, sizeof(pbuf)) before the system call. Thoughts?

CI: https://ci.nodejs.org/job/libuv-test-commit/65/

@saghul
Copy link
Member

saghul commented Jun 22, 2016

LGTM. Isn't memset kinda wasteful if the entire structure is going to be overwritten right after? I'd say we keep this patch as is.

Don't call uv__to_stat() when the stat/fstat/lstat system call fails;
the stack-allocated buffer contains only garbage in that case.

Not a very serious bug it's technically undefined behavior and it made
valgrind squawk.

Introduced in commit 499c797 ("unix, windows: nanosecond resolution
for uv_fs_[fl]stat").

PR-URL: libuv#921
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
@cjihrig
Copy link
Contributor

cjihrig commented Jun 22, 2016

LGTM as is.

@bnoordhuis bnoordhuis closed this Jun 22, 2016
@bnoordhuis bnoordhuis deleted the fix-stat-garbage branch June 22, 2016 17:05
@bnoordhuis bnoordhuis merged commit 34ee257 into libuv:v1.x Jun 22, 2016
@bnoordhuis
Copy link
Member Author

Isn't memset kinda wasteful if the entire structure is going to be overwritten right after?

The idea is that the caller doesn't see uninitialized values (and I'd implement it as if (ret != 0) memset(buf, 0, sizeof(*buf)) post-system call for efficiency reasons.)

OTOH (and IMO), it's arguably the caller's responsibility to check the return code. I wanted to present a balanced view. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants