summaryrefslogtreecommitdiffstats
path: root/lib/libc/nls
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-05-10 04:28:17 +0000
committerache <ache@FreeBSD.org>1997-05-10 04:28:17 +0000
commitd4628da6086df0893152fd9af3f131b7a4fdc54c (patch)
tree90b80d791b9780e545ae36e7f99ebdb9f092eb60 /lib/libc/nls
parent66ef383d7aaa96b79c8b97505c77365d1a8eb94f (diff)
downloadFreeBSD-src-d4628da6086df0893152fd9af3f131b7a4fdc54c.zip
FreeBSD-src-d4628da6086df0893152fd9af3f131b7a4fdc54c.tar.gz
Cleanup
Plug failure memory leaks Use issetugid now PR: 3492
Diffstat (limited to 'lib/libc/nls')
-rw-r--r--lib/libc/nls/msgcat.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
index 69c6316..17d6111 100644
--- a/lib/libc/nls/msgcat.c
+++ b/lib/libc/nls/msgcat.c
@@ -1,4 +1,4 @@
-/* $Id: msgcat.c,v 1.8 1997/03/24 06:15:07 imp Exp $ */
+/* $Id: msgcat.c,v 1.9 1997/03/25 05:36:37 imp Exp $ */
/***********************************************************
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
@@ -87,7 +87,7 @@ int type;
{
char path[MAXPATHLEN];
__const char *catpath = NULL;
- char *nlspath, *tmppath = NULL;
+ char *nlspath;
char *lang;
long len;
char *base, *cptr, *pathP;
@@ -101,11 +101,8 @@ int type;
} else {
if ((lang = (char *) getenv("LANG")) == NULL)
lang = "C";
- /* XXX Should really be issetguid(), but we don't have that */
- if ((nlspath = (char *) getenv("NLSPATH")) == NULL ||
- getuid() != geteuid() || getgid() != getegid()) {
+ if ((nlspath = (char *) getenv("NLSPATH")) == NULL || issetugid())
nlspath = "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L";
- }
len = strlen(nlspath);
base = cptr = (char *) malloc(len + 2);
@@ -139,7 +136,6 @@ int type;
}
}
free(base);
- if (tmppath) free(tmppath);
if (!catpath) return(0);
}
@@ -287,8 +283,8 @@ nl_catd catd;
/* Note that only malloc failures are allowed to return an error */
#define ERRNAME "Message Catalog System"
-#define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); return(0);}
-#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); return(NLERR);}
+#define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); free(cat); return(0);}
+#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); free(cat); return(NLERR);}
static nl_catd loadCat( catpath, type)
__const char *catpath;
@@ -305,22 +301,25 @@ int type;
cat->loadType = type;
if ((cat->fd = open(catpath, O_RDONLY)) < 0) {
+ free(cat);
return(0);
}
- fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
+ (void)fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
if (read(cat->fd, &header, sizeof(header)) != sizeof(header)) CORRUPT();
if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
if (header.majorVer != MCMajorVer) {
+ free(cat);
fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", ERRNAME,
catpath, header.majorVer, MCMajorVer);
return(0);
}
if (header.numSets <= 0) {
+ free(cat);
fprintf(stderr, "%s: %s has %ld sets!\n", ERRNAME, catpath,
header.numSets);
return(0);
@@ -332,11 +331,13 @@ int type;
nextSet = header.firstSet;
for (i = 0; i < cat->numSets; ++i) {
- if (lseek(cat->fd, nextSet, 0) == -1) CORRUPT();
+ if (lseek(cat->fd, nextSet, 0) == -1)
+ {free(cat->sets); CORRUPT();}
/* read in the set header */
set = cat->sets + i;
- if (read(cat->fd, set, sizeof(*set)) != sizeof(*set)) CORRUPT();
+ if (read(cat->fd, set, sizeof(*set)) != sizeof(*set))
+ {free(cat->sets); CORRUPT();}
/* if it's invalid, skip over it (and backup 'i') */
@@ -349,6 +350,7 @@ int type;
if (cat->loadType == MCLoadAll) {
nl_catd res;
if ((res = loadSet(cat, set)) <= 0) {
+ free(cat->sets);
if (res == -1) NOSPACE();
CORRUPT();
}
@@ -372,15 +374,23 @@ MCSetT *set;
/* Get the data */
if (lseek(cat->fd, set->data.off, 0) == -1) return(0);
if ((set->data.str = (char *) malloc(set->dataLen)) == NULL) return(-1);
- if (read(cat->fd, set->data.str, set->dataLen) != set->dataLen) return(0);
+ if (read(cat->fd, set->data.str, set->dataLen) != set->dataLen) {
+ free(set->data.str); return(0);
+ }
/* Get the messages */
- if (lseek(cat->fd, set->u.firstMsg, 0) == -1) return(0);
- if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) return(-1);
+ if (lseek(cat->fd, set->u.firstMsg, 0) == -1) {
+ free(set->data.str); return(0);
+ }
+ if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
+ free(set->data.str); return(-1);
+ }
for (i = 0; i < set->numMsgs; ++i) {
msg = set->u.msgs + i;
- if (read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) return(0);
+ if (read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) {
+ free(set->u.msgs); free(set->data.str); return(0);
+ }
if (msg->invalid) {
--i;
continue;
@@ -390,8 +400,3 @@ MCSetT *set;
set->invalid = False;
return(1);
}
-
-
-
-
-
OpenPOWER on IntegriCloud