From a0468efe8603e3ec13d9a0ffa2cb253baf462740 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Dec 2023 02:10:23 +0100 Subject: [PATCH] btrfs-progs: reset errno before strtoull() strtoull may return the boundary values, if the callers could expect that and verify it then the errno must be reset before the call. Signed-off-by: David Sterba --- common/parse-utils.c | 1 + common/sysfs-utils.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/common/parse-utils.c b/common/parse-utils.c index 74542a79..3d9a6d63 100644 --- a/common/parse-utils.c +++ b/common/parse-utils.c @@ -158,6 +158,7 @@ u64 parse_size_from_string(const char *s) error("size value '%s' is less equal than 0", s); exit(1); } + errno = 0; ret = strtoull(s, &endptr, 10); if (endptr == s) { error("size value '%s' is invalid", s); diff --git a/common/sysfs-utils.c b/common/sysfs-utils.c index 6bc546d9..3c4a3ad3 100644 --- a/common/sysfs-utils.c +++ b/common/sysfs-utils.c @@ -108,6 +108,7 @@ int sysfs_read_file_u64(const char *name, u64 *value) if (ret < 0) goto out; /* Raw value in any numeric format should work, followed by a newline. */ + errno = 0; *value = strtoull(str, NULL, 0); out: close(fd); @@ -127,6 +128,7 @@ int sysfs_read_fsid_file_u64(int fd, const char *name, u64 *value) if (ret < 0) goto out; /* Raw value in any numeric format should work, followed by a newline. */ + errno = 0; *value = strtoull(str, NULL, 0); out: close(fd);