[前][次][番号順一覧][スレッド一覧]

ruby-changes:13367

From: nobu <ko1@a...>
Date: Mon, 28 Sep 2009 23:32:43 +0900 (JST)
Subject: [ruby-changes:13367] Ruby:r25136 (trunk): * dln.c (load_lib, dln_find_exe_r): env string may be overwritten.

nobu	2009-09-28 23:31:01 +0900 (Mon, 28 Sep 2009)

  New Revision: 25136

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25136

  Log:
    * dln.c (load_lib, dln_find_exe_r): env string may be overwritten.

  Modified files:
    trunk/ChangeLog
    trunk/dln.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25135)
+++ ChangeLog	(revision 25136)
@@ -1,5 +1,7 @@
-Mon Sep 28 22:46:16 2009  Nobuyoshi Nakada  <nobu@r...>
+Mon Sep 28 23:30:59 2009  Nobuyoshi Nakada  <nobu@r...>
 
+	* dln.c (load_lib, dln_find_exe_r): env string may be overwritten.
+
 	* dln.c (dln_{exit,loaderror,memerror,notimplement}): renamed as
 	  independent names.
 
Index: dln.c
===================================================================
--- dln.c	(revision 25135)
+++ dln.c	(revision 25136)
@@ -907,12 +907,13 @@
     int lib_offset;
 };
 
-char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
+const char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
 
 static int
 load_lib(const char *lib)
 {
     char *path, *file, fbuf[MAXPATHLEN];
+    char *envpath = 0;
     char armagic[SARMAG];
     int fd, size;
     struct ar_hdr ahdr;
@@ -942,8 +943,10 @@
     /* if path is still NULL, use "." for path. */
     path = getenv("DLN_LIBRARY_PATH");
     if (path == NULL) path = dln_librrb_ary_path;
+    else path = envpath = strdup(path);
 
     file = dln_find_file_r(lib, path, fbuf, sizeof(fbuf));
+    if (envpath) free(envpath);
     fd = open(file, O_RDONLY);
     if (fd == -1) goto syserr;
     size = read(fd, armagic, SARMAG);
@@ -1498,8 +1501,11 @@
 char *
 dln_find_exe_r(const char *fname, const char *path, char *buf, size_t size)
 {
+    char *envpath = 0;
+
     if (!path) {
 	path = getenv(PATH_ENV);
+	if (path) path = envpath = strdup(path);
     }
 
     if (!path) {
@@ -1509,7 +1515,9 @@
 	path = "/usr/local/bin:/usr/ucb:/usr/bin:/bin:.";
 #endif
     }
-    return dln_find_1(fname, path, buf, size, 1);
+    buf = dln_find_1(fname, path, buf, size, 1);
+    if (envpath) free(envpath);
+    return buf;
 }
 
 char *

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]