Use a more explicit check on readlink result

This should help the static analyzer to understand the code.
This commit is contained in:
Andrea Mazzoleni 2017-12-12 00:01:25 +01:00
parent ee10b6f9a6
commit 976338f84c
2 changed files with 2 additions and 2 deletions

View file

@ -247,7 +247,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s
int ret;
ret = readlink(path_next, linkto, sizeof(linkto));
if (ret < 0 || ret == sizeof(linkto)) {
if (ret < 0 || ret >= PATH_MAX) {
/* LCOV_EXCL_START */
log_fatal("Error in readlink symlink '%s'. %s.\n", path_next, strerror(errno));
exit(EXIT_FAILURE);

View file

@ -448,7 +448,7 @@ static int devuuid_dev(uint64_t device, char* uuid, size_t uuid_size)
/* resolve the link */
pathprint(path, sizeof(path), "/dev/disk/by-uuid/%s", dd->d_name);
ret = readlink(path, buf, sizeof(buf));
if (ret < 0 || ret == sizeof(buf)) {
if (ret < 0 || ret >= PATH_MAX) {
log_tag("uuid:by-uuid:%u:%u: readlink(/dev/disk/by-uuid/%s) failed, %s\n", major(device), minor(device), dd->d_name, strerror(errno));
/* generic error, ignore and continue the search */
continue;