mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Cc: Alexander Monakov <amonakov@ispras.ru>
Subject: [PATCH] env: avoid leaving dangling pointers in __env_map
Date: Sun,  6 Mar 2016 20:22:38 +0300	[thread overview]
Message-ID: <1457284958-12429-1-git-send-email-amonakov@ispras.ru> (raw)

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



             reply	other threads:[~2016-03-06 17:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-06 17:22 Alexander Monakov [this message]
2016-03-06 19:41 ` [libc-test][PATCH] add putenv double-free regression test Alexander Monakov
2016-03-06 21:13   ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457284958-12429-1-git-send-email-amonakov@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).