]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslocks: (bugfix) don't set rawdata in COL_PID if rawdata is null
authorMasatake YAMATO <yamato@redhat.com>
Tue, 13 Jan 2026 10:03:26 +0000 (19:03 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Tue, 13 Jan 2026 10:19:53 +0000 (19:19 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lslocks.c
tests/expected/lslocks/filter
tests/ts/lslocks/filter

index 00dff4f765fd308f9eada0c3dd84a7479c22e9f8..8d79af4d794e822940ac4386ca4b4d124762f81e 100644 (file)
@@ -635,7 +635,7 @@ static char *get_data(struct lslocks *lslocks, struct lock *l, int num,
                break;
        case COL_PID:
                xasprintf(&str, "%d", l->pid);
-               if (l->pid >= 0)
+               if (l->pid >= 0 && rawdata)
                        *rawdata = (uint64_t)l->pid;
                break;
        case COL_TYPE:
index 74a53f22ff9e9a3d7f0e0c6624d948a9c27435af..52c2f4756f2c7705fe3222286f1053f2711613ea 100644 (file)
@@ -1,3 +1,5 @@
+#### crash when printing PID column ####
+PID: 0
 #### flock  (common) ####
 # -Q PID == ...
 test_mkfds FLOCK WRITE 4K 0 0 0
index cc5aceceef4e5f737d62b7a08a50b937ce29c9fa..90bb63a2c06a7bf1c88cfd8947f68b512a597f5c 100755 (executable)
@@ -49,6 +49,18 @@ if ! dd if=/dev/zero of="$FILE" bs=$SIZE count=1 status=none; then
     ts_skip "failed to create a temporary file"
 fi
 
+do_lslocks_flock_crash()
+{
+    local pid=$1
+
+    echo "#### crash when printing PID column ####"
+    [[ "$pid" == $("$TS_CMD_LSLOCKS" \
+                      -r -n -p "$PID" \
+                      -Q 'PATH =~ '"'.*/$FILE'"" and TYPE == 'FLOCK'" \
+                      -o PID) ]]
+    echo "PID: $?"
+}
+
 do_lslocks_common()
 {
     local pid=$1
@@ -132,6 +144,7 @@ do_lslocks_fcntl()
                       "$FILE" \
                       "$TS_HELPER_MKFDS" nop; }
     if read -r -u "${MKFDS[0]}" PID; then
+       do_lslocks_flock_crash $PID
        do_lslocks_common $PID flock
        echo DONE >&"${MKFDS[1]}"
     fi