Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Manszewski, Christoph" <christoph.manszewski@intel.com>
To: Peter Senna Tschudin <peter.senna@linux.intel.com>,
	igt-dev@lists.freedesktop.org
Subject: Re: [PATCH i-g-t] lib/igt_list: igt_list_empty() Detect uninitialized list
Date: Tue, 23 Sep 2025 10:14:08 +0200	[thread overview]
Message-ID: <0a1dc4a1-a910-43c5-b078-4e9cf3cc3f91@intel.com> (raw)
In-Reply-To: <20250922162340.20034-1-peter.senna@linux.intel.com>

Hi Peter,

On 22.09.2025 18:23, Peter Senna Tschudin wrote:
> Add a check to igt_list_empty() to return true if the list head pointer
> or its next/prev pointers are NULL, preventing segfaults when operating
> on uninitialized or potentially broken lists.
> 
> Signed-off-by: Peter Senna Tschudin <peter.senna@linux.intel.com>
> ---
>   lib/igt_list.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/lib/igt_list.c b/lib/igt_list.c
> index 37ae139c4..f77aef7dd 100644
> --- a/lib/igt_list.c
> +++ b/lib/igt_list.c
> @@ -79,5 +79,9 @@ int igt_list_length(const struct igt_list_head *head)
>   
>   bool igt_list_empty(const struct igt_list_head *head)
>   {
> +	/* Detect uninitialized / potentially broken list */
> +	if (!head || !head->next || !head->prev)
> +		return true;
> +

Without this change:
1. Passing an uninitialized list is a bug
2. The function doesn't check any condition and returns 'normally' 
regardless

With this change:
1. Passing an uninitialized list is a bug (still)
2. The function *may* detect an uninitialized list which is a bug but 
returns 'normally' regardless

If we are adding a check that catches some invalid/buggy condition the 
reasonable thing to do would be to assert/abort.

Regards,
Christoph


>   	return head->next == head;
>   }


  parent reply	other threads:[~2025-09-23  8:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-22 16:23 [PATCH i-g-t] lib/igt_list: igt_list_empty() Detect uninitialized list Peter Senna Tschudin
2025-09-22 19:49 ` ✓ Xe.CI.BAT: success for " Patchwork
2025-09-22 19:56 ` ✗ i915.CI.BAT: failure " Patchwork
2025-09-23  1:16 ` ✓ Xe.CI.Full: success " Patchwork
2025-09-23  8:14 ` Manszewski, Christoph [this message]
2025-09-23  9:20   ` [PATCH i-g-t] " Peter Senna Tschudin
2025-09-23  9:32     ` Manszewski, Christoph

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a1dc4a1-a910-43c5-b078-4e9cf3cc3f91@intel.com \
    --to=christoph.manszewski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=peter.senna@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox