[vlc-commits] commit: Detect dangerous use of environment variables at run-time ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sun Apr 11 17:40:13 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 11 18:37:46 2010 +0300| [4e1ff3a1aa04411220a586365e0eda596cd9e506] | committer: Rémi Denis-Courmont 

Detect dangerous use of environment variables at run-time

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4e1ff3a1aa04411220a586365e0eda596cd9e506
---

 bin/override.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/bin/override.c b/bin/override.c
index 048c8fe..5098a7d 100644
--- a/bin/override.c
+++ b/bin/override.c
@@ -77,4 +77,43 @@ static void *getsym (const char *name)
     ({ typeof (func) *sym = getsym ( # func); sym (__VA_ARGS__); })
 
 
+/*** Environment ***
+ *
+ * "Conforming multi-threaded applications shall not use the environ variable
+ *  to access or modify any environment variable while any other thread is
+ *  concurrently modifying any environment variable." -- POSIX.
+ *
+ * Some evil libraries modify the environment. We currently ignore the calls as
+ * they could crash the process. This may cause funny behaviour though. */
+int putenv (char *str)
+{
+    if (override)
+    {
+        LOG("Blocked", "\"%s\"", str);
+        return 0;
+    }
+    return CALL(putenv, str);
+}
+
+int setenv (const char *name, const char *value, int overwrite)
+{
+    if (override)
+    {
+        LOG("Blocked", "\"%s\", \"%s\", %d", name, value, overwrite);
+        return 0;
+    }
+    return CALL(setenv, name, value, overwrite);
+}
+
+int unsetenv (const char *name)
+{
+    if (override)
+    {
+        LOG("Blocked", "\"%s\"", name);
+        return 0;
+    }
+    return CALL(unsetenv, name);
+}
+
+
 #endif /* __ELF__ */



More information about the vlc-commits mailing list