From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>,
Alex Radocea <alex@supernetworks.org>
Subject: [PATCH 3/5] p2putil: fix crash/remove side effect parsing adv service info
Date: Thu, 29 Feb 2024 09:07:32 -0800 [thread overview]
Message-ID: <20240229170734.1498918-3-prestwoj@gmail.com> (raw)
In-Reply-To: <20240229170734.1498918-1-prestwoj@gmail.com>
The input queue pointer was being initialized unconditionally so if
parsing fails the out pointer is still set after the queue is
destroyed. This causes a crash during cleanup.
Instead use a temporary pointer while parsing and only after parsing
has finished do we set the out pointer.
Reported-By: Alex Radocea <alex@supernetworks.org>
---
src/p2putil.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/p2putil.c b/src/p2putil.c
index 5313b34c..faf151a5 100644
--- a/src/p2putil.c
+++ b/src/p2putil.c
@@ -541,7 +541,8 @@ static void p2p_clear_advertised_service_descriptor(void *data)
static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len,
void *data)
{
- struct l_queue **out = data;
+ struct l_queue **q = data;
+ struct l_queue *out = NULL;
while (len) {
struct p2p_advertised_service_descriptor *desc;
@@ -557,11 +558,11 @@ static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len,
if (!l_utf8_validate((const char *) attr + 7, name_len, NULL))
goto error;
- if (!*out)
- *out = l_queue_new();
+ if (!out)
+ out = l_queue_new();
desc = l_new(struct p2p_advertised_service_descriptor, 1);
- l_queue_push_tail(*out, desc);
+ l_queue_push_tail(out, desc);
desc->advertisement_id = l_get_le32(attr + 0);
desc->wsc_config_methods = l_get_be16(attr + 4);
@@ -572,10 +573,12 @@ static bool extract_p2p_advertised_service_info(const uint8_t *attr, size_t len,
len -= 7 + name_len;
}
+ *q = out;
+
return true;
error:
- l_queue_destroy(*out, p2p_clear_advertised_service_descriptor);
+ l_queue_destroy(out, p2p_clear_advertised_service_descriptor);
return false;
}
--
2.34.1
next prev parent reply other threads:[~2024-02-29 17:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 17:07 [PATCH 1/5] auto-t: end process_io on HUP signal, detect process crash James Prestwood
2024-02-29 17:07 ` [PATCH 2/5] auto-t: Add frame fuzzing test James Prestwood
2024-02-29 17:07 ` James Prestwood [this message]
2024-02-29 17:07 ` [PATCH 4/5] p2putil: initialize all parsing structures to zero James Prestwood
2024-02-29 17:07 ` [PATCH 5/5] p2putil: check length of client info description James Prestwood
2024-02-29 20:36 ` [PATCH 1/5] auto-t: end process_io on HUP signal, detect process crash Denis Kenzior
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=20240229170734.1498918-3-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=alex@supernetworks.org \
--cc=iwd@lists.linux.dev \
/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