selftests/ipc: Use IPC_STAT to get queue information
PATCH 1/1 selftests/ipc: Use IPC_STAT to get queue information
dump_queue() finds the message queue's stats by brute-forcing kernel indexes 0..255 with MSG_STAT and comparing the returned identifier with msgque->msq_id. This misses queues whose index is 256 or larger, and if no match is found the loop ends and the code goes on using a stale or uninitialized struct msqid_ds.
The identifier is already known, so query it directly with IPC_STAT. This removes the loop and reports a failure if the queue cannot be queried.
--- tools/testing/selftests/ipc/msgque.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
tools/testing/selftests/ipc/msgque.c +5 -13
@@ -130,21 +130,13 @@ err:int dump_queue (struct msgque_data *msgque) {struct msqid_ds ds; -int kern_id;int i, ret; -for (kern_id =0 ; kern_id <256 ; kern_id++) { - ret =msgctl (kern_id,MSG_STAT , &ds); -if (ret <0 ) { -if (errno ==EINVAL ) -continue ; -ksft_test_result_fail ("Failed to get stats for IPC queue with id %d\n" , - kern_id); -return -errno; - } - -if (ret == msgque->msq_id) -break ; + ret =msgctl (msgque->msq_id,IPC_STAT , &ds); +if (ret <0 ) { +ksft_test_result_fail ("Failed to get stats for IPC queue with id %d\n" , + msgque->msq_id); +return -errno; } msgque->messages =malloc (sizeof (struct msg1 ) * ds.msg_qnum);
Signature · 1 line
2.47.3
Hi Shuah,
Just a gentle ping on this patch.
Thanks,
Muhammed
Muhammed Sariyildiz <[email protected]>, 1 Kas 2026 Paz, 22:48 tarihinde şunu yazdı:
Quoted 50 lines
dump_queue()finds the message queue's stats by brute-forcing kernel indexes 0..255 withMSG_STATand comparing the returned identifier withmsgque->msq_id. This misses queues whose index is 256 or larger, and if no match is found the loop ends and the code goes on using a stale or uninitialized structmsqid_ds.The identifier is already known, so query it directly with
IPC_STAT. This removes the loop and reports a failure if the queue cannot be queried.Signed-off-by Muhammed Sariyildiz <[email protected]>--- tools/testing/selftests/ipc/msgque.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)tools/testing/selftests/ipc/msgque.c +5
-14@@ -130,21 +130,13 @@ err:int dump_queue (struct msgque_data *msgque) {struct msqid_ds ds; -int kern_id;int i, ret; -for (kern_id =0 ; kern_id <256 ; kern_id++) { - ret =msgctl (kern_id,MSG_STAT , &ds); -if (ret <0 ) { -if (errno ==EINVAL ) -continue ; -ksft_test_result_fail ("Failed to get stats for IPC queue with id %d\n" , - kern_id); -return -errno; - } - -if (ret == msgque->msq_id) -break ; + ret =msgctl (msgque->msq_id,IPC_STAT , &ds); +if (ret <0 ) { +ksft_test_result_fail ("Failed to get stats for IPC queue with id %d\n" , + msgque->msq_id); +return -errno; } msgque->messages =malloc (sizeof (struct msg1 ) * ds.msg_qnum); --2.47.3