The atoll() error check `if (offset == 0 && errno != 0)` can falsely
trigger because errno is not cleared before the call. Library
initialization code (e.g. libcap calling prctl(PR_CAPBSET_READ) which
fails with EINVAL) can leave errno set to a non-zero value. When the
caller passes offset=0 (a valid value), atoll() returns 0 without
modifying errno, and the stale errno causes the helper to print usage
and exit.
This caused btrfs/333 to fail consistently on systems where libcap is
linked, since every call with offset 0 would bail out.
Fix by clearing errno before the atoll() calls in both
btrfs_encoded_read and btrfs_encoded_write helpers.
Signed-off-by: Leo Martins <loemra.dev@gmail.com>
Reviewed-by: Mark Harmstone <mark@harmstone.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
filename = argv[2];
+ errno = 0;
offset = atoll(argv[3]);
if (offset == 0 && errno != 0) {
usage();
filename = argv[2];
+ errno = 0;
offset = atoll(argv[3]);
if (offset == 0 && errno != 0) {
usage();