git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] regexec: work around macOS TRE leak on invalid UTF-8

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2026, 00:41 UTC
Message-ID
<xmqqse52bpa9.fsf@gitster.g>
In-Reply-To
<20260728052538.12429-1-chungmin@chungminlee.com>
Chungmin Lee <chungmin@chungminlee.com> writes:
Show 29 quoted lines
> diff --git a/Makefile b/Makefile
> index 1cec251..81075c3 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2264,6 +2264,10 @@ ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
>  	COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
>  	COMPAT_OBJS += compat/regcomp_enhanced.o
>  endif
> +ifdef DARWIN_REGEXEC
> +	COMPAT_OBJS += compat/darwin/regexec.o
> +	BASIC_CFLAGS += -DDARWIN_REGEXEC
> +endif
>  endif
>  ifdef NATIVE_CRLF
>  	BASIC_CFLAGS += -DNATIVE_CRLF
> diff --git a/compat/darwin.h b/compat/darwin.h
> new file mode 100644
> index 0000000..6fbdc34
> --- /dev/null
> +++ b/compat/darwin.h
> @@ -0,0 +1,8 @@
> +#ifndef COMPAT_DARWIN_H
> +#define COMPAT_DARWIN_H
> +
> +int darwin_regexec_buf(const regex_t *preg, const char *buf, size_t size,
> +		       size_t nmatch, regmatch_t pmatch[], int eflags);
> +#define regexec_buf darwin_regexec_buf
> +
> +#endif

This iteration looks much easier to grok, at least to me. Two things:

 * The name of the header, <compat/darwin.h>, sounds so nice and
   central, that those who care a lot more about macOS than I do may
   want to consolidate other support for the peculiarities macOS has
   also into it.  I personally do not have a strong opinion.
 * We'd need a comment near the beginning of Makefile, like other
   symbolis like NO_FINK and NO_APPLE_COMMMON_CRYPTO do, to tell the
   users when to define this new symbol.

The latter I would feel strong enough, so here is a sample update in a squashable form. If you have reasons to send a new iteration, you are free to include it. After waiting for comments from others for a few days, if you still don't have reasons to send an update, you can just tell me to squash the change on my end (if you agree with the change, that is).

diff --git c/Makefile w/Makefile
index 81075c38a2..ed2868ce10 100644
--- c/Makefile
+++ w/Makefile
@@ -110,6 +110,9 @@ include shared.mak
 # Define USE_HOMEBREW_LIBICONV to link against libiconv installed by
 # Homebrew, if present.
 #
+# Define DARWIN_REGEXEC if regexec() in your platform regex library
+# leaks when fed an invalid UTF-8 sequence.
+#
 # Define NO_APPLE_COMMON_CRYPTO if you are building on Darwin/Mac OS X
 # and do not want to use Apple's CommonCrypto library.  This allows you
 # to provide your own OpenSSL library, for example from MacPorts.
Previous: Chungmin LeeNext: Patrick Steinhardt
Message 4 of 5 in “regexec: work around macOS TRE memory leak on invalid UTF-8”
  1. regexec: work around macOS TRE memory leak on invalid UTF-8Chungmin Lee, Jul 22, 2026
  2. Junio C HamanoJul 24, 2026
  3. regexec: work around macOS TRE leak on invalid UTF-8Chungmin Lee, Jul 28, 2026
  4. Junio C HamanoJul 29, 2026
  5. Patrick SteinhardtAug 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.