]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
btrfs: fix stale errno check in btrfs_encoded_read/write helpers
authorLeo Martins <loemra.dev@gmail.com>
Tue, 24 Mar 2026 19:09:52 +0000 (12:09 -0700)
committerZorro Lang <zlang@kernel.org>
Wed, 1 Apr 2026 15:07:08 +0000 (23:07 +0800)
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>
src/btrfs_encoded_read.c
src/btrfs_encoded_write.c

index 3ee0d8b005d906344c82dbffe538474c7ad8fb36..c7c25b74d80f4142a4c34b6ba421bd1b618d2c16 100644 (file)
@@ -178,6 +178,7 @@ int main(int argc, char *argv[])
 
        filename = argv[2];
 
+       errno = 0;
        offset = atoll(argv[3]);
        if (offset == 0 && errno != 0) {
                usage();
index 7e46d9fed7925f89d1e8eaa0c3fe5d374734495a..bc05cc3bedc7a6b742c95fb77c8611c938f0f94c 100644 (file)
@@ -179,6 +179,7 @@ int main(int argc, char *argv[])
 
        filename = argv[2];
 
+       errno = 0;
        offset = atoll(argv[3]);
        if (offset == 0 && errno != 0) {
                usage();