]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: fix octal conversion logic
authorDarrick J. Wong <djwong@kernel.org>
Wed, 23 Nov 2022 17:09:17 +0000 (09:09 -0800)
committerCarlos Maiolino <cem@kernel.org>
Fri, 9 Dec 2022 09:18:19 +0000 (10:18 +0100)
Fix the backwards boolean logic here, which results in weird behavior.

# xfs_db -x -c /dev/sda
xfs_db> print fname
fname = "\000\000\000\000\000\000\000\000\000\000\000\000"
xfs_db> write fname "mo\0h5o"
fname = "mo\005o\000\000\000\000\000\000\000\000"
xfs_db> print fname
fname = "mo\005o\000\000\000\000\000\000\000\000"

Notice that we passed in octal-zero, 'h', '5', 'o', but the fs label is
set to octal-5, 'o' because of the incorrect loop logic.  -Wlogical-op
found this one.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
db/write.c

index 70cb0518d0113a08286bae276053a9fe3d77a713..6c67e839a9ebfc74922559968a35b4acbff72f74 100644 (file)
@@ -479,7 +479,7 @@ convert_oct(
                if (arg[count] == '\0')
                        break;
 
-               if ((arg[count] < '0') && (arg[count] > '7'))
+               if ((arg[count] < '0') || (arg[count] > '7'))
                        break;
        }
 
@@ -553,7 +553,7 @@ convert_arg(
 
                        /* do octal conversion */
                        if (*ostr == '\\') {
-                               if (*(ostr + 1) >= '0' || *(ostr + 1) <= '7') {
+                               if (*(ostr + 1) >= '0' && *(ostr + 1) <= '7') {
                                        ret = convert_oct(ostr + 1, &octval);
                                        *rbuf++ = octval;
                                        ostr += ret + 1;