about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-05-16 10:13:54 -0400
committerUlrich Drepper <drepper@gmail.com>2011-05-16 10:13:54 -0400
commitea389b12b3b65c4a7fa91fa76f8c99867eb37865 (patch)
tree93cc7bd2191d9b0c66bc31ad923d8134a70f23ec /stdlib
parent68a3f91fcad464c4737c1eaed4ae0bf539801fb2 (diff)
downloadglibc-ea389b12b3b65c4a7fa91fa76f8c99867eb37865.tar.gz
glibc-ea389b12b3b65c4a7fa91fa76f8c99867eb37865.tar.xz
glibc-ea389b12b3b65c4a7fa91fa76f8c99867eb37865.zip
Handle long variable names in putenv
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/putenv.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/stdlib/putenv.c b/stdlib/putenv.c
index 4e8693403a..d97eb5423a 100644
--- a/stdlib/putenv.c
+++ b/stdlib/putenv.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 94, 95, 96, 97, 98, 99, 11 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -57,14 +57,31 @@ putenv (string)
 
   if (name_end != NULL)
     {
+      char *name;
 #ifdef _LIBC
-      char *name = strndupa (string, name_end - string);
+      int use_malloc = !__libc_use_alloca (name_end - string + 1);
+      if (__builtin_expect (use_malloc, 0))
+	{
+	  name = strndup (string, name_end - string);
+	  if (name == NULL)
+	    return -1;
+	}
+      else
+	name = strndupa (string, name_end - string);
 #else
-      char *name = alloca (name_end - string + 1);
+# define use_malloc 1
+      name = malloc (name_end - string + 1);
+      if (name == NULL)
+	return -1;
       memcpy (name, string, name_end - string);
       name[name_end - string] = '\0';
 #endif
-      return __add_to_environ (name, NULL, string, 1);
+      int result = __add_to_environ (name, NULL, string, 1);
+
+      if (__builtin_expect (use_malloc, 0))
+	free (name);
+
+      return result;
     }
 
   __unsetenv (string);