summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--dln.c12
2 files changed, 13 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e5b2ebe..9ba33c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
-Mon Sep 28 22:46:16 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Sep 28 23:30:59 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * dln.c (load_lib, dln_find_exe_r): env string may be overwritten.
* dln.c (dln_{exit,loaderror,memerror,notimplement}): renamed as
independent names.
diff --git a/dln.c b/dln.c
index bc7406c..bf72ade 100644
--- a/dln.c
+++ b/dln.c
@@ -907,12 +907,13 @@ struct symdef {
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 @@ load_lib(const char *lib)
/* 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 @@ static char *dln_find_1(const char *fname, const char *path, char *buf, size_t s
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 @@ dln_find_exe_r(const char *fname, const char *path, char *buf, size_t size)
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 *