mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] env: avoid leaving dangling pointers in __env_map
@ 2016-03-06 17:22 Alexander Monakov
  2016-03-06 19:41 ` [libc-test][PATCH] add putenv double-free regression test Alexander Monakov
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2016-03-06 17:22 UTC (permalink / raw)
  To: musl; +Cc: Alexander Monakov

This is the minimal fix for __putenv leaving a pointer to freed heap
storage in __env_map array, which could later on lead to errors such
as double-free.
---
This was discovered by code inspection after Rich asked me to develop
testcases for another environment-related patch in a recent thread.
There's another known issue due to logic errors in surrounding code
(a memory leak due to putenv never freeing storage allocated by preceding
setenv), but that is planned to be addressed with a patch overhauling the
implementation.

Thanks.
Alexander

 src/env/putenv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/env/putenv.c b/src/env/putenv.c
index 4042869..7153042 100644
--- a/src/env/putenv.c
+++ b/src/env/putenv.c
@@ -30,6 +30,7 @@ int __putenv(char *s, int a)
 				}
 			} else {
 				free(__env_map[j]);
+				__env_map[j] = s;
 			}
 		}
 	}
-- 
2.1.3



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-06 21:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-06 17:22 [PATCH] env: avoid leaving dangling pointers in __env_map Alexander Monakov
2016-03-06 19:41 ` [libc-test][PATCH] add putenv double-free regression test Alexander Monakov
2016-03-06 21:13   ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).