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

FIX: Wrong sizeof argument of coverity defects(CID 147639) #5198

Merged
merged 1 commit into from
Oct 10, 2016

Conversation

GeLiXin
Copy link
Contributor

@GeLiXin GeLiXin commented Sep 30, 2016

There are 4 defects of wrong size/sizeof argument.
CID 147634, 147635, 147636 seems like false positives.

But 147639 seems really risky:
When array is passed as parameter, it degenerate into pointer,
so the sizeof(path) in is_shorthand_path()always get return value of 8, not the string lenght we want.

Signed-off-by: GeLiXin [email protected]

@@ -548,7 +548,7 @@ is_shorthand_path(const char *arg, char *path,
return (0);
}

strlcpy(path, arg, sizeof (path));
strlcpy(path, arg, path_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is clearly wrong and we need to use a passed size. Similarly you should pass the new path_size to zfs_resolve_shortname() above and remove the assumption that the buffer is MAXPATHLEN.

@behlendorf
Copy link
Contributor

@GeLiXin can you incorporate the review feedback and rebase this on master.

@GeLiXin GeLiXin force-pushed the wrongsize branch 2 times, most recently from 459a29c to 9a64b9e Compare October 8, 2016 03:22
@GeLiXin
Copy link
Contributor Author

GeLiXin commented Oct 8, 2016

@behlendorf I'm really sorry for feedback for such a long time, as I just come back after a 7 day's holiday of Chinese national day.
I have fixed this PR as review and rebased it now. Please take a review again.

@@ -660,7 +660,8 @@ make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log)
/* After is_whole_disk() check restore original passed path */
strlcpy(path, arg, MAXPATHLEN);
} else {
err = is_shorthand_path(arg, path, &statbuf, &wholedisk);
err = is_shorthand_path(arg, path, MAXPATHLEN,
&statbuf, &wholedisk);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[style] Four space indent for continued lines.

+       err = is_shorthand_path(arg, path, MAXPATHLEN,
+           &statbuf, &wholedisk);

@behlendorf
Copy link
Contributor

@GeLiXin no problem. Hopefully you enjoyed the vacation. Just one minor style issue to fix and then this LGTM. @rlaager if you've got a minute it would be great to get another review for this fix.

@GeLiXin GeLiXin force-pushed the wrongsize branch 2 times, most recently from 44a4e2e to 56a1807 Compare October 8, 2016 04:43
@GeLiXin
Copy link
Contributor Author

GeLiXin commented Oct 8, 2016

@behlendorf I modified a little to fit different path size which not assumpt it to be MAXPATHLEN any more.
but I didn't find space indent in these two lines you point out, only tabs here.

+       err = is_shorthand_path(arg, path, sizeof (path),
+           &statbuf, &wholedisk);

@behlendorf
Copy link
Contributor

@GeLiXin I should have been clearer. Continued lines should be indented by four spaces after being tab aligned. I posted the fixed line, you'll need to convert that last tab to four space instead. You can see this same style used in the rest of the file whenever a line is continued.

The removal of MAXPATHLEN in favor of sizeof is fine.

} else {
err = is_shorthand_path(arg, path, &statbuf, &wholedisk);
err = is_shorthand_path(arg, path, sizeof (path),
&statbuf, &wholedisk);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[style]

There are 4 defects of wrong size/sizeof argument.
CID 147639?147635?147634 seems like false positives.

But 147639 seems really risky:
When array is passed as parameter, it degenerate into pointer,
so the sizeof(path) in is_shorthand_path() always get return value of 8, not the string lenght we want.

Signed-off-by: GeLiXin <[email protected]>
@GeLiXin
Copy link
Contributor Author

GeLiXin commented Oct 9, 2016

@behlendorf I get your point now, thanks. And I'm done!

@behlendorf behlendorf merged commit 8c8cf8a into openzfs:master Oct 10, 2016
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.

2 participants