Memory management fixes and b4 config
cover Memory management fixes and b4 config
Fix memory management issues found by Claude Opus 4.6, and add configuration for b4 to simplify sending patches.
---
Paul Barker (3):
pseudo_setupenvp: Allocate space for new env vars if needed
pseudo_setupenvp: Handle malloc failure safely Add b4 configuration
.b4-config | 4 ++++ pseudo_util.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)
---
base-commit: 56e1f8df4761da60e41812fc32b1de797d1765e9
change-id: 20260320-some-fixes-d87097cdbeb5
Best regards,
Signature · 1 line
Paul Barker
PATCH 1/3 pseudo_setupenvp: Allocate space for new env vars if needed
If LD_LIBRARY_PATH or LD_PRELOAD were not included in the existing environment, we need to make space for them. Otherwise we have the potential for a buffer overflow. It's pretty unlikely as it can only be triggered when an application running under pseudo calls execve(), posix_spawn() or posix_spawnp() with a cleaned environment that doesn't include the above variables, but it's better to be safe than sorry.
Issue found by Claude Opus 4.6, but fix implemented by me.
--- pseudo_util.c | 8 ++++++++ 1 file changed, 8 insertions(+)
pseudo_util.c +8 -0
@@ -1141,6 +1141,14 @@ pseudo_setupenvp(char * const *envp) { ++env_count; } +/* If LD_PRELOAD or LD_LIBRARY_PATH were not included in the existing +* environment, we need to make space for them. +*/ +if (!ld_preload) + env_count++; +if (!ld_library_path) + env_count++; +for (i =0 ; pseudo_env[i].key; i++) { size_pseudoenv++; }
Signature · 1 line
2.43.0
PATCH 2/3 pseudo_setupenvp: Handle malloc failure safely
In reply to Paul BarkerIf malloc() fails, don't try to write to a NULL pointer. Instead skip the snprintf() call in the same way we do in other malloc error handling in this function.
Issue found by Claude Opus 4.6, but fix implemented by me.
--- pseudo_util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
pseudo_util.c +6 -4
@@ -1201,9 +1201,10 @@ pseudo_setupenvp(char * const *envp) {char *newenv =malloc (len);if (!newenv) {pseudo_diag ("fatal: can't allocate new %s variable.\n" ,PRELINK_LIBRARIES ); + }else { +snprintf (newenv, len,PRELINK_LIBRARIES "=%s" , ld_preload); + new_envp[j++] = newenv; } -snprintf (newenv, len,PRELINK_LIBRARIES "=%s" , ld_preload); - new_envp[j++] = newenv;free (ld_preload); } }
@@ -1229,9 +1230,10 @@ pseudo_setupenvp(char * const *envp) {char *newenv =malloc (len);if (!newenv) {pseudo_diag ("fatal: can't allocate new variable.\n" ); + }else { +snprintf (newenv, len,"%s=%s" , pseudo_env[i].key, pseudo_env[i].value); + new_envp[j++] = newenv; } -snprintf (newenv, len,"%s=%s" , pseudo_env[i].key, pseudo_env[i].value); - new_envp[j++] = newenv; } } new_envp[j++] =NULL ;
Signature · 1 line
2.43.0
PATCH 3/3 Add b4 configuration
In reply to Paul BarkerMake contribution easier by including a .b4-config file, pointing at the correct mailing list and prepending [pseudo] to patches.
--- .b4-config | 4 ++++ 1 file changed, 4 insertions(+)
.b4-config new file +4 -0
@@ -0,0 +1,4 @@ +[b4] + send-series-to = [email protected] + prep-pre-flight-checks = disable-needs-auto-to-cc, disable-needs-checking + send-prefixes = pseudo
Signature · 1 line
2.43.0
Re: [yocto-patches] [PATCH pseudo 3/3] Add b4 configuration
Hi Paul,
Quoted 3 lines · Paul Barker via lists.yoctoproject.org
Make contribution easier by including a .b4-config file, pointing at the correct mailing list and prepending [pseudo] to patches.
Thanks!
Quentin
The set looks good to me. I'm surprised about the possible alloc/buffer overflow.
I suspect it's never triggered because we over allocate for the PSEUDO variables just before that, but relying on that behavior is not safe, so your change should ensure we have enough space at all times.
--Mark
Quoted 17 lines · Paul Barker
Fix memory management issues found by Claude Opus 4.6, and add configuration for b4 to simplify sending patches.
---
Paul Barker (3):
pseudo_setupenvp: Allocate space for new env vars if needed
pseudo_setupenvp: Handle malloc failure safely Add b4 configuration.b4-config | 4 ++++ pseudo_util.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)---
base-commit:56e1f8df4761da60e41812fc32b1de797d1765e9
change-id: 20260320-some-fixes-d87097cdbeb5Best regards,