From: Masatake YAMATO Date: Tue, 13 Jan 2026 10:03:26 +0000 (+0900) Subject: lslocks: (bugfix) don't set rawdata in COL_PID if rawdata is null X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=093d21775bcaffad5850d87c6ac0a8eb8b20845b;p=thirdparty%2Futil-linux.git lslocks: (bugfix) don't set rawdata in COL_PID if rawdata is null Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index 00dff4f76..8d79af4d7 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -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: diff --git a/tests/expected/lslocks/filter b/tests/expected/lslocks/filter index 74a53f22f..52c2f4756 100644 --- a/tests/expected/lslocks/filter +++ b/tests/expected/lslocks/filter @@ -1,3 +1,5 @@ +#### crash when printing PID column #### +PID: 0 #### flock (common) #### # -Q PID == ... test_mkfds FLOCK WRITE 4K 0 0 0 diff --git a/tests/ts/lslocks/filter b/tests/ts/lslocks/filter index cc5acecee..90bb63a2c 100755 --- a/tests/ts/lslocks/filter +++ b/tests/ts/lslocks/filter @@ -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