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

Don't use uninitialized variable #1816

Merged
merged 1 commit into from
Oct 11, 2018
Merged

Conversation

csware
Copy link

@csware csware commented Sep 4, 2018

The usage of the uninitialized variable findbuf on https://github.com/git-for-windows/git/blob/master/compat/mingw.c#L858 causes undefined behavior in libgit (if if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { is false).

This is fixed by initializing it properly which is only present in Git for Windows but not vanilla Git.

@dscho
Copy link
Member

dscho commented Sep 4, 2018

The usage of the uninitialized variable findbuf on https://github.com/git-for-windows/git/blob/master/compat/mingw.c#L858 causes undefined behavior in libgit (if if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { is false).

Is it? I see the only user to be

 		buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes,
			findbuf.dwReserved0, file_name);

... and file_attr_to_st_mode() uses the tag parameter (i.e. the parameter as which findbuf.dwReserved0 is passed) only in this expression:

 	if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
 		tag == IO_REPARSE_TAG_SYMLINK) {

In other words, the tag variable is only ever used if fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT is true.

Having said that, with a more accurate commit message, I would love to merge this, as it makes it easier to reason about the correctness of the code.
I.e.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
@csware
Copy link
Author

csware commented Sep 6, 2018

@dscho
Updated.

@dscho dscho merged commit b85dc5c into git-for-windows:master Oct 11, 2018
@dscho
Copy link
Member

dscho commented Oct 11, 2018

Thank you so much, especially for your patience!

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

2 participants