This commit is contained in:
mrg 1997-04-22 12:27:34 +00:00
parent f542cc77da
commit 071eac5167
2 changed files with 31 additions and 24 deletions

View File

@ -91,6 +91,10 @@ setlocale(category, locale)
int found, i, len;
char *env, *r;
/*
* XXX potential security problem here with set-id programs
* being able to read files the user can not normally read.
*/
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
PathLocale = _PATH_LOCALE;
@ -123,7 +127,7 @@ setlocale(category, locale)
if (!env)
env = "C";
(void) strncpy(new_categories[category], env, 31);
(void)strncpy(new_categories[category], env, 31);
new_categories[category][31] = 0;
if (!category) {
for (i = 1; i < _LC_LAST; ++i) {
@ -133,7 +137,7 @@ setlocale(category, locale)
new_categories[i][31] = 0;
}
}
} else if (category) {
} else if (category) {
(void)strncpy(new_categories[category], locale, 31);
new_categories[category][31] = 0;
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: catopen.c,v 1.9 1996/06/21 06:21:04 jtc Exp $ */
/* $NetBSD: catopen.c,v 1.10 1997/04/22 12:28:01 mrg Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -67,18 +67,21 @@ _catopen(name, oflag)
nl_catd catd;
if (name == NULL || *name == '\0')
return (nl_catd) -1;
return (nl_catd)-1;
/* absolute or relative path? */
if (strchr (name, '/'))
if (strchr(name, '/'))
return load_msgcat(name);
if ((nlspath = getenv ("NLSPATH")) == NULL) {
/*
* XXX potential security problem here if this is used in a
* set-id program, and NLSPATH or LANG are set to read files
* the user normally does not have access to.
*/
if ((nlspath = getenv("NLSPATH")) == NULL)
nlspath = NLS_DEFAULT_PATH;
}
if ((lang = getenv ("LANG")) == NULL) {
if ((lang = getenv("LANG")) == NULL)
lang = NLS_DEFAULT_LANG;
}
s = nlspath;
t = tmppath;
@ -113,7 +116,7 @@ _catopen(name, oflag)
*t = '\0';
catd = load_msgcat(tmppath);
if (catd != (nl_catd) -1)
if (catd != (nl_catd)-1)
return catd;
if (*s)
@ -121,7 +124,7 @@ _catopen(name, oflag)
t = tmppath;
} while (*s);
return (nl_catd) -1;
return (nl_catd)-1;
}
static nl_catd
@ -133,30 +136,30 @@ load_msgcat(path)
void *data;
int fd;
if ((fd = open (path, O_RDONLY)) == -1)
return (nl_catd) -1;
if ((fd = open(path, O_RDONLY)) == -1)
return (nl_catd)-1;
if (fstat(fd, &st) != 0) {
close (fd);
return (nl_catd) -1;
return (nl_catd)-1;
}
data = mmap(0, (size_t) st.st_size, PROT_READ, MAP_SHARED, fd, 0);
data = mmap(0, (size_t)st.st_size, PROT_READ, MAP_SHARED, fd, 0);
close (fd);
if (data == (void *) -1) {
munmap(data, (size_t) st.st_size);
return (nl_catd) -1;
if (data == (void *)-1) {
munmap(data, (size_t)st.st_size);
return (nl_catd)-1;
}
if (ntohl(((struct _nls_cat_hdr *) data)->__magic) != _NLS_MAGIC) {
munmap(data, (size_t) st.st_size);
return (nl_catd) -1;
if (ntohl(((struct _nls_cat_hdr *)data)->__magic) != _NLS_MAGIC) {
munmap(data, (size_t)st.st_size);
return (nl_catd)-1;
}
if ((catd = malloc (sizeof (*catd))) == 0) {
munmap(data, (size_t) st.st_size);
return (nl_catd) -1;
if ((catd = malloc(sizeof (*catd))) == 0) {
munmap(data, (size_t)st.st_size);
return (nl_catd)-1;
}
catd->__data = data;