unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 7/7] xap_helper.h: fix double-free on OpenBSD hdestroy
Date: Wed, 30 Aug 2023 05:10:45 +0000	[thread overview]
Message-ID: <20230830051045.330641-8-e@80x24.org> (raw)
In-Reply-To: <20230830051045.330641-1-e@80x24.org>

hdestroy on OpenBSD assumes each key in the table can be freed,
so use strdup to fulfil that requirement.

This behavior differs from tested behavior on glibc and FreeBSD,
as well as what I can see from reading the musl and NetBSD
source code.  OpenBSD may be the only relevant OS which requires
this workaround.
---
 lib/PublicInbox/xap_helper.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index 92210511..17085adc 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -460,6 +460,16 @@ static enum exc_iter dump_roots_iter(struct req *req,
 	return ITER_OK;
 }
 
+static char *hsearch_enter_key(char *s)
+{
+#if defined(__OpenBSD__) /* hdestroy frees each key */
+	char *ret = strdup(s);
+	if (!ret) perror("strdup");
+	return ret;
+#endif // glibc, musl, FreeBSD, NetBSD do not free keys
+	return s;
+}
+
 static bool cmd_dump_roots(struct req *req)
 {
 	CLEANUP_DUMP_ROOTS struct dump_roots_tmp drt = {};
@@ -511,7 +521,8 @@ static bool cmd_dump_roots(struct req *req)
 	}
 	for (size_t i = 0; i < tot; ) {
 		ENTRY e;
-		e.key = drt.entries[i++];
+		e.key = hsearch_enter_key(drt.entries[i++]);
+		if (!e.key) return false;
 		e.data = drt.entries[i++];
 		if (!hsearch(e, ENTER)) {
 			warn("hsearch(%s => %s, ENTER)", e.key,

  parent reply	other threads:[~2023-08-30  5:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30  5:10 [PATCH 0/7] various build fixes + OpenBSD compat Eric Wong
2023-08-30  5:10 ` [PATCH 1/7] treewide: drop MSG_EOR with AF_UNIX+SOCK_SEQPACKET Eric Wong
2023-08-30  5:10 ` [PATCH 2/7] Makefile.PL: fix syntax for ASan and valgrind targets Eric Wong
2023-08-30  5:10 ` [PATCH 3/7] Makefile.PL: depend on autodie, at least for tests Eric Wong
2023-08-30  5:10 ` [PATCH 4/7] t/kqnotify: improve test reliability on OpenBSD Eric Wong
2023-08-30  5:10 ` [PATCH 5/7] xap_helper.h: don't compress debug sections " Eric Wong
2023-08-30  5:10 ` [PATCH 6/7] xap_helper.h: limit stderr assignment to glibc+FreeBSD Eric Wong
2023-08-30  5:10 ` Eric Wong [this message]
2023-08-30 12:34 ` [PATCH 0/7] various build fixes + OpenBSD compat, [PATCH 7/7] xap_helper.h: fix double-free on OpenBSD hdestroy Štěpán Němec
2023-08-30 21:18   ` Eric Wong
2023-08-31  9:11     ` Štěpán Němec
2023-08-31 17:26       ` Štěpán Němec
2023-09-01 11:09         ` Eric Wong
2023-09-02 10:54           ` Štěpán Němec
2023-09-02 11:07             ` [PATCH v2] Clarify Inline::C dependency (optional on Linux, required elsewhere) Štěpán Němec
2023-09-02 18:50               ` Eric Wong
2023-09-02 19:08                 ` Štěpán Němec
2023-09-02 19:44                   ` Eric Wong
2023-09-02 20:45                     ` Štěpán Němec
2023-09-02 20:56                       ` Eric Wong

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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20230830051045.330641-8-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).