From 45a8651447663a048319b2b80bbf9d31f33d025d Mon Sep 17 00:00:00 2001 From: James Lucas Date: Fri, 19 May 2023 10:37:10 +1000 Subject: [PATCH 1/2] Fix bug GH-11246 cli/get_set_process_title initialisation failure on MacOS Patch for PHP >= 8.2 due to commit b468d6f --- NEWS | 3 +++ sapi/cli/ps_title.c | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 3d5888b896227..b906ec51c6fcc 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ PHP NEWS . Fixed bug GH-11222 (foreach by-ref may jump over keys during a rehash). (Bob) +- CLI: + . Fixed bug GH-11246 (cli/get_set_process_title fails on MacOS). (James Lucas) + - Exif: . Fixed bug GH-10834 (exif_read_data() cannot read smaller stream wrapper chunk sizes). (nielsdos) diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 8ff7ef719e17f..81d8ae8a85b76 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -169,19 +169,20 @@ char** save_ps_args(int argc, char** argv) end_of_area = argv[i] + strlen(argv[i]); } + if (!is_contiguous_area) { + goto clobber_error; + } + /* * check for contiguous environ strings following argv */ for (i = 0; is_contiguous_area && (environ[i] != NULL); i++) { - if (end_of_area + 1 != environ[i]) { - is_contiguous_area = false; + if (end_of_area + 1 == environ[i]) { + end_of_area = environ[i] + strlen(environ[i]); + } else { + is_contiguous_area = false; } - end_of_area = environ[i] + strlen(environ[i]); - } - - if (!is_contiguous_area) { - goto clobber_error; } ps_buffer = argv[0]; From 5c7ac5c9491a599faebc6f6b7deb281fe3825293 Mon Sep 17 00:00:00 2001 From: James Lucas Date: Sun, 21 May 2023 22:14:44 +1000 Subject: [PATCH 2/2] Don't break early finding the end of the environ array --- sapi/cli/ps_title.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 81d8ae8a85b76..11ee5919c1652 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -176,12 +176,10 @@ char** save_ps_args(int argc, char** argv) /* * check for contiguous environ strings following argv */ - for (i = 0; is_contiguous_area && (environ[i] != NULL); i++) + for (i = 0; environ[i] != NULL; i++) { if (end_of_area + 1 == environ[i]) { end_of_area = environ[i] + strlen(environ[i]); - } else { - is_contiguous_area = false; } }