-
Notifications
You must be signed in to change notification settings - Fork 241
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
-Wextra: with extra cheese #801
Conversation
daf99a0
to
abf9119
Compare
abf9119
to
316ee71
Compare
25f4911
to
bd992d2
Compare
2fab6a8
to
69dbe8e
Compare
69dbe8e
to
c3e4de0
Compare
v2 changes:
Tested locally: $ sudo docker build -f ./share/containers/debian.dockerfile . | ovr
Successfully built a7538f4af26b Range diff:
|
c3e4de0
to
19c9bae
Compare
v2b changes:
|
19c9bae
to
1da15f3
Compare
v2c changes:
|
1da15f3
to
2018034
Compare
v2d changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all thank you for providing the unit tests for STRLCPY. I think it makes easier to understand its usage and to detect any failure.
Second, since you are changing is_valid_user_name()
and it is a small function, would you mind adding a unit test for it?
Finally, what was the output of your investigation of a warning in copydir.c
? I see you mention it in the commit message but no other action is taken.
By the way, I added some comments inline.
The warnings are below: $ touch lib/copydir.c
$ make
make all-recursive
make[1]: Entering directory '/home/alx/src/shadow/shadow/wextra'
Making all in lib
make[2]: Entering directory '/home/alx/src/shadow/shadow/wextra/lib'
CC libshadow_la-copydir.lo
copydir.c: In function 'copy_special':
copydir.c:687:38: warning: unused parameter 'src' [-Wunused-parameter]
687 | copy_special(const struct path_info *src, const struct path_info *dst,
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~
copydir.c:688:19: warning: unused parameter 'reset_selinux' [-Wunused-parameter]
688 | bool reset_selinux,
| ^
copydir.c: In function 'copy_file':
copydir.c:743:28: warning: unused parameter 'reset_selinux' [-Wunused-parameter]
743 | bool reset_selinux,
| ^ Analysis of $ grepc -ntfd copy_special .
./lib/copydir.c:686:
static int
copy_special(const struct path_info *src, const struct path_info *dst,
bool reset_selinux,
const struct stat *statp, const struct timespec mt[],
uid_t old_uid, uid_t new_uid,
gid_t old_gid, gid_t new_gid)
{
#if defined(WITH_SELINUX)
if (set_selinux_file_context(dst->full_path, statp->st_mode & S_IFMT) != 0)
return -1;
#endif
if (mknodat(dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) == -1)
return -1;
if (chownat_if_needed(dst, statp, old_uid, new_uid, old_gid, new_gid) == -1)
return -1;
if (fchmodat(dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) == -1)
return -1;
#if defined(WITH_ACL)
if (perm_copy_path(src, dst, &ctx) == -1 && errno != 0)
return -1;
#endif
#if defined(WITH_ATTR)
/*
* If the third parameter is NULL, all extended attributes
* except those that define Access Control Lists are copied.
* ACLs are excluded by default because copying them between
* file systems with and without ACL support needs some
* additional logic so that no unexpected permissions result.
*/
if (!reset_selinux) {
if (attr_copy_path(src, dst, NULL, &ctx) == -1 && errno != 0)
return -1;
}
#endif
if (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) == -1)
return -1;
return 0;
} Some parameters are unused depending on the configuration. We could use $ grepc -itm -C3 unused .
./lib/defines.h-
./lib/defines.h-/* To be used for verified unused parameters */
./lib/defines.h-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
./lib/defines.h:# define unused __attribute__((unused))
./lib/defines.h-# define NORETURN __attribute__((__noreturn__))
./lib/defines.h-# define format_attr(type, index, check) __attribute__((format (type, index, check)))
./lib/defines.h-#else
./lib/defines.h:# define unused
./lib/defines.h-# define NORETURN
./lib/defines.h-# define format_attr(type, index, check)
./lib/defines.h-#endif Analysis of $ grepc -ntfd copy_file .
./lib/copydir.c:742:
static int copy_file (const struct path_info *src, const struct path_info *dst,
bool reset_selinux,
const struct stat *statp, const struct timespec mt[],
uid_t old_uid, uid_t new_uid,
gid_t old_gid, gid_t new_gid)
{
int err = 0;
int ifd;
int ofd;
ifd = openat (src->dirfd, src->name, O_RDONLY|O_NOFOLLOW|O_CLOEXEC);
if (ifd < 0) {
return -1;
}
#ifdef WITH_SELINUX
if (set_selinux_file_context (dst->full_path, S_IFREG) != 0) {
(void) close (ifd);
return -1;
}
#endif /* WITH_SELINUX */
ofd = openat (dst->dirfd, dst->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600);
if ( (ofd < 0)
|| (fchown_if_needed (ofd, statp,
old_uid, new_uid, old_gid, new_gid) != 0)
|| (fchmod (ofd, statp->st_mode & 07777) != 0)
#ifdef WITH_ACL
|| ( (perm_copy_fd (src->full_path, ifd, dst->full_path, ofd, &ctx) != 0)
&& (errno != 0))
#endif /* WITH_ACL */
#ifdef WITH_ATTR
/*
* If the third parameter is NULL, all extended attributes
* except those that define Access Control Lists are copied.
* ACLs are excluded by default because copying them between
* file systems with and without ACL support needs some
* additional logic so that no unexpected permissions result.
*/
|| ( !reset_selinux
&& (attr_copy_fd (src->full_path, ifd, dst->full_path, ofd, NULL, &ctx) != 0)
&& (errno != 0))
#endif /* WITH_ATTR */
) {
if (ofd >= 0) {
(void) close (ofd);
}
(void) close (ifd);
return -1;
}
while (true) {
char buf[8192];
ssize_t cnt;
cnt = read (ifd, buf, sizeof buf);
if (cnt < 0) {
if (errno == EINTR) {
continue;
}
(void) close (ofd);
(void) close (ifd);
return -1;
}
if (cnt == 0) {
break;
}
if (write_full(ofd, buf, cnt) == -1) {
(void) close (ofd);
(void) close (ifd);
return -1;
}
}
(void) close (ifd);
if (close (ofd) != 0) {
return -1;
}
if (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0) {
return -1;
}
return err;
} Same thing. Depending on the configuration. |
Yes, I can do that! :) |
I'll mark it as draft until that test is written. |
2018034
to
9ff74c1
Compare
v3 changes:
|
9ff74c1
to
8387cf1
Compare
v4 changes:
|
8387cf1
to
859e44a
Compare
v5 changes:
|
643b176
to
efe6672
Compare
v8 changes:
|
Thanks, looks good to me. Please add the one comment and i will merge. |
The one comment. :) |
efe6672
to
77f63bd
Compare
v8b changes:
|
Signed-off-by: Alejandro Colomar <[email protected]>
I used size_t because: sysconf(3) can return -1 if the value is not supported, but then it can only mean that there's no limit. Having no limit is the same as having a limit of SIZE_MAX (to which -1 is converted). Signed-off-by: Alejandro Colomar <[email protected]>
See uintmax_t(3type). While at it, remove the useless cast to (void). Signed-off-by: Alejandro Colomar <[email protected]>
I was investigating a warning in this function, but the code was inscrutable. Signed-off-by: Alejandro Colomar <[email protected]>
strtol(3) doesn't specify a return value if (value == endptr). It is always an error, if (value==endptr). Signed-off-by: Alejandro Colomar <[email protected]>
The multiplication was already invoking UB. The test was flawed. Use __builtin_mul_overflow() instead. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
It's only used in certain builds. This is to silence a -Wunused-parameter warning. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This simplifies the code a little bit, and prepares for the next commits, which will clean up further. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This prepares for the next patch, which will invert the logic of the conditional. Signed-off-by: Alejandro Colomar <[email protected]>
Since failure() is [[noreturn]], we can invert the conditional so that we don't need an else. This silences a -Wunused-parameter warning. Signed-off-by: Alejandro Colomar <[email protected]>
…pare warning Signed-off-by: Alejandro Colomar <[email protected]>
77f63bd
to
ecc8f17
Compare
v9 changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Merging...
I used size_t because: sysconf(3) can return -1 if the value is not supported, but then it can only mean that there's no limit. Having no limit is the same as having a limit of SIZE_MAX (to which -1 is converted). Signed-off-by: Alejandro Colomar <[email protected]> Cherry-picked-from: 6be85b0 ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning") [alx: This is to cherry-pick the next commit without conflict] Link: <#801> Link: <#935> Cc: Serge Hallyn <[email protected]> Cc: Tobias Stoeckmann <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Add -Wextra to have extra warnings.