coreutils/backport-putenv-Don-t-crash-upon-out-of-memory.patch
h30032433 80b999f39c sync patches from community
(cherry picked from commit 0c9adb86cb84d4f086e9660601e48e84d9a2dc48)
2024-09-12 09:24:29 +08:00

31 lines
794 B
Diff

From adb76c754290c328a88438af89e491ece7e6a9c5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 6 Jun 2024 02:24:44 +0200
Subject: [PATCH] putenv: Don't crash upon out-of-memory.
* lib/putenv.c (_unsetenv): Handle malloc failure.
Reference:https://github.com/coreutils/gnulib/commit/adb76c754290c328a88438af89e491ece7e6a9c5
Conflict:delete ChangeLog
---
lib/putenv.c | 2 ++
1 files changed, 2 insertions(+)
diff --git a/lib/putenv.c b/lib/putenv.c
index 525d12ae..1d70717e 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -92,6 +92,8 @@ _unsetenv (const char *name)
{
int putenv_result;
char *name_ = malloc (len + 2);
+ if (name_ == NULL)
+ return -1;
memcpy (name_, name, len);
name_[len] = '=';
name_[len + 1] = 0;
--
2.43.0