1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-09-28 14:31:01 +00:00
parent fc831f638a
commit 4097c096e8
2 changed files with 13 additions and 3 deletions

View file

@ -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.

12
dln.c
View file

@ -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 *