Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src Pull up following revision(s) (requested by christos in t...



details:   https://anonhg.NetBSD.org/src/rev/232c2940158a
branches:  netbsd-6
changeset: 774063:232c2940158a
user:      riz <riz%NetBSD.org@localhost>
date:      Mon May 07 16:47:22 2012 +0000

description:
Pull up following revision(s) (requested by christos in ticket #222):
        include/stdlib.h: revision 1.98
        lib/libc/compat/stdlib/Makefile.inc: revision 1.3
        lib/libc/compat/include/stdlib.h: revision 1.5
        lib/libc/compat/stdlib/compat_putenv.c: revision 1.1
        lib/libc/compat/stdlib/compat_putenv.c: revision 1.2
PR/46360: YAMAMOTO Takashi: Restore NetBSD-5 compatibility with putenv()
copying the passed string (which is not ToG compliant), instead of using
it directly in the environment arrat as it should. Needs to be pulled up
to NetBSd-6.
use setenv so that we don't leak memory.

diffstat:

 include/stdlib.h                       |   6 +-
 lib/libc/compat/include/stdlib.h       |   4 +-
 lib/libc/compat/stdlib/Makefile.inc    |   4 +-
 lib/libc/compat/stdlib/compat_putenv.c |  84 ++++++++++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 5 deletions(-)

diffs (137 lines):

diff -r a4d3f2ec083a -r 232c2940158a include/stdlib.h
--- a/include/stdlib.h  Mon May 07 16:38:43 2012 +0000
+++ b/include/stdlib.h  Mon May 07 16:47:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stdlib.h,v 1.97 2011/03/16 00:48:34 christos Exp $     */
+/*     $NetBSD: stdlib.h,v 1.97.6.1 2012/05/07 16:47:22 riz Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -160,7 +160,9 @@
         seed48(unsigned short[3]);
 void    srand48(long);
 
-int     putenv(char *);
+#ifndef __LIBC12_SOURCE__
+int     putenv(char *) __RENAME(__putenv50);
+#endif
 #endif
 
 
diff -r a4d3f2ec083a -r 232c2940158a lib/libc/compat/include/stdlib.h
--- a/lib/libc/compat/include/stdlib.h  Mon May 07 16:38:43 2012 +0000
+++ b/lib/libc/compat/include/stdlib.h  Mon May 07 16:47:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stdlib.h,v 1.4 2009/01/26 15:05:56 drochner Exp $      */
+/*     $NetBSD: stdlib.h,v 1.4.10.1 2012/05/07 16:47:22 riz Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,6 +38,8 @@
 
 void    unsetenv(const char *);
 int     __unsetenv13(const char *);
+int     putenv(char *);
+int     __putenv50(char *);
 __aconst char *devname(int32_t, mode_t);
 __aconst char *__devname50(dev_t, mode_t);
 
diff -r a4d3f2ec083a -r 232c2940158a lib/libc/compat/stdlib/Makefile.inc
--- a/lib/libc/compat/stdlib/Makefile.inc       Mon May 07 16:38:43 2012 +0000
+++ b/lib/libc/compat/stdlib/Makefile.inc       Mon May 07 16:47:22 2012 +0000
@@ -1,5 +1,5 @@
-#      $NetBSD: Makefile.inc,v 1.2 2006/03/11 21:07:18 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.2.46.1 2012/05/07 16:47:22 riz Exp $
 
 .PATH: ${COMPATDIR}/stdlib
 CPPFLAGS+=-I${COMPATDIR}/stdlib -I${COMPATDIR}/../stdlib
-SRCS+=compat_unsetenv.c 
+SRCS+=compat_putenv.c compat_unsetenv.c
diff -r a4d3f2ec083a -r 232c2940158a lib/libc/compat/stdlib/compat_putenv.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/compat/stdlib/compat_putenv.c    Mon May 07 16:47:22 2012 +0000
@@ -0,0 +1,84 @@
+/*     $NetBSD: compat_putenv.c,v 1.2.2.2 2012/05/07 16:47:22 riz Exp $        */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: compat_putenv.c,v 1.2.2.2 2012/05/07 16:47:22 riz Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#define __LIBC12_SOURCE__
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <compat/include/stdlib.h>
+
+#include "env.h"
+#include "reentrant.h"
+#include "local.h"
+
+#ifdef __weak_alias
+__weak_alias(putenv,_putenv)
+#endif
+
+__warn_references(putenv,
+    "warning: reference to compatibility putenv();"
+    " include <stdlib.h> for correct reference")
+
+/*
+ * putenv(name) --
+ *     This version implicitly copies the string for compatibility.
+ */
+int
+putenv(char *name)
+{
+       size_t l_name;
+       char *copy;
+       int rv;
+
+       _DIAGASSERT(name != NULL);
+
+        l_name = __envvarnamelen(name, true); 
+        if (l_name == 0) { 
+                errno = EINVAL;
+                return -1;
+        }
+
+       if ((copy = strdup(name)) == NULL)
+               return -1;
+       copy[l_name++] = '\0';
+
+       rv = setenv(copy, copy + l_name, 1);
+
+       free(copy);
+       return rv;
+}



Home | Main Index | Thread Index | Old Index