diff options
| author | lukem <lukem@NetBSD.org> | 1997-08-14 02:06:15 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 1997-08-14 02:06:15 +0000 |
| commit | 0bba8ce38dc3fc2ac54a02ad9b3d01b361fd60aa (patch) | |
| tree | da95737ffc4198a060e66a044518325f6e05ab52 /libexec | |
| parent | b327731e261588b21bf8c9c6e229c1a80df4beef (diff) | |
* don't depend upon buffer returned by fgetln() to remain. fix mainly
from Tatoku Ogaito <tacha@tera.fukui-med.ac.jp> in [bin/3967]
* fgetln() doesn't \0 terminate its string. look for the \n and replace
it with \0 (if no \n, ignore the line - it's most likely corrupt)
* more intensive checks on strdup() returns (not a current mem leak,
but depended upon code elsewhere to cleanup - not good)
* cleanup some syslog error messages
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/ftpd/conf.c | 51 | ||||
| -rw-r--r-- | libexec/ftpd/ftpd.c | 14 |
2 files changed, 47 insertions, 18 deletions
diff --git a/libexec/ftpd/conf.c b/libexec/ftpd/conf.c index 59cf6953003..4ad1f36522b 100644 --- a/libexec/ftpd/conf.c +++ b/libexec/ftpd/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.4 1997/07/31 00:08:04 jtc Exp $ */ +/* $NetBSD: conf.c,v 1.5 1997/08/14 02:06:15 lukem Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: conf.c,v 1.4 1997/07/31 00:08:04 jtc Exp $"); +__RCSID("$NetBSD: conf.c,v 1.5 1997/08/14 02:06:15 lukem Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -75,7 +75,6 @@ parse_conf(findclass) int none, match; char *endp; char *class, *word, *arg; - char *types, *disable, *convcmd; const char *infile; int line; unsigned int timeout; @@ -115,8 +114,14 @@ parse_conf(findclass) while ((buf = fgetln(f, &len)) != NULL) { none = match = 0; line++; - if (buf[len - 1] == '\n') - buf[--len] = '\0'; + if (len < 1) + continue; + if (buf[len - 1] != '\n') { + syslog(LOG_WARNING, + "%s line %d is partially truncated?", infile, line); + continue; + } + buf[--len] = '\0'; if ((p = strchr(buf, '#')) != NULL) *p = '\0'; if (EMPTYSTR(buf)) @@ -134,6 +139,8 @@ parse_conf(findclass) continue; if (strcasecmp(word, "conversion") == 0) { + char *suffix, *types, *disable, *convcmd; + if (EMPTYSTR(arg)) { syslog(LOG_WARNING, "%s line %d: %s requires a suffix", @@ -145,6 +152,11 @@ parse_conf(findclass) convcmd = buf; if (convcmd) convcmd += strspn(convcmd, " \t"); + suffix = strdup(arg); + if (suffix == NULL) { + syslog(LOG_WARNING, "can't strdup"); + continue; + } if (none || EMPTYSTR(types) || EMPTYSTR(disable) || EMPTYSTR(convcmd)) { types = NULL; @@ -154,10 +166,21 @@ parse_conf(findclass) types = strdup(types); disable = strdup(disable); convcmd = strdup(convcmd); + if (types == NULL || disable == NULL || + convcmd == NULL) { + syslog(LOG_WARNING, "can't strdup"); + if (types) + free(types); + if (disable) + free(disable); + if (convcmd) + free(convcmd); + continue; + } } for (conv = curclass.conversions; conv != NULL; conv = conv->next) { - if (strcmp(conv->suffix, arg) == 0) + if (strcmp(conv->suffix, suffix) == 0) break; } if (conv == NULL) { @@ -170,7 +193,7 @@ parse_conf(findclass) conv->next = curclass.conversions; curclass.conversions = conv; } - REASSIGN(conv->suffix, arg); + REASSIGN(conv->suffix, suffix); REASSIGN(conv->types, types); REASSIGN(conv->disable, disable); REASSIGN(conv->command, convcmd); @@ -291,14 +314,15 @@ show_chdir_messages(code) /* Check if this directory has already been visited */ if (getcwd(cwd, sizeof(cwd) - 1) == NULL) { - syslog(LOG_WARNING, "show_chdir_messages: can't malloc"); + syslog(LOG_WARNING, "can't malloc"); return; } if (sl_find(slist, cwd) != NULL) return; - if ((cp = strdup(cwd)) == NULL) { - syslog(LOG_WARNING, "show_chdir_messages: can't strdup"); + cp = strdup(cwd); + if (cp == NULL) { + syslog(LOG_WARNING, "can't strdup"); return; } sl_add(slist, cp); @@ -410,9 +434,14 @@ do_conversion(fname) o_errno = errno; for (cp = curclass.conversions; cp != NULL; cp = cp->next) { + if (cp->suffix == NULL) { + syslog(LOG_WARNING, + "cp->suffix==NULL in conv list; SHOULDN'T HAPPEN!"); + continue; + } if ((base = strend(fname, cp->suffix)) == NULL) continue; - if (cp->suffix == NULL || cp->types == NULL || + if (cp->types == NULL || cp->disable == NULL || cp->command == NULL) continue; /* Is it enabled? */ diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index be1ccc9c5d1..15a9c94ca57 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftpd.c,v 1.29 1997/07/21 05:13:10 mrg Exp $ */ +/* $NetBSD: ftpd.c,v 1.30 1997/08/14 02:06:17 lukem Exp $ */ /* * Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994 @@ -44,7 +44,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)ftpd.c 8.5 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: ftpd.c,v 1.29 1997/07/21 05:13:10 mrg Exp $"); +__RCSID("$NetBSD: ftpd.c,v 1.30 1997/08/14 02:06:17 lukem Exp $"); #endif #endif /* not lint */ @@ -245,7 +245,7 @@ main(argc, argv, envp) debug = 0; /* set this here so klogin can use it... */ - (void)snprintf(ttyline, sizeof ttyline, "ftp%d", getpid()); + (void)snprintf(ttyline, sizeof(ttyline), "ftp%d", getpid()); while ((ch = getopt(argc, argv, "a:dlt:T:u:v")) != EOF) { switch (ch) { @@ -759,7 +759,7 @@ retrieve(cmd, name) if (cmd) { char line[BUFSIZ]; - (void)snprintf(line, sizeof line, cmd, name), name = line; + (void)snprintf(line, sizeof(line), cmd, name), name = line; fin = ftpd_popen(line, "r", 1), closefunc = ftpd_pclose; st.st_size = -1; st.st_blksize = BUFSIZ; @@ -939,7 +939,7 @@ dataconn(name, size, mode) file_size = size; byte_count = 0; if (size != (off_t) -1) - (void)snprintf(sizebuf, sizeof sizebuf, " (%qd bytes)", + (void)snprintf(sizebuf, sizeof(sizebuf), " (%qd bytes)", (long long)size); else sizebuf[0] = '\0'; @@ -1737,11 +1737,11 @@ send_file_list(whichf) dir->d_namlen == 2) continue; - (void)snprintf(nbuf, sizeof nbuf, "%s/%s", dirname, + (void)snprintf(nbuf, sizeof(nbuf), "%s/%s", dirname, dir->d_name); /* - * We have to do a stat to insure it's + * We have to do a stat to ensure it's * not a directory or special file. */ if (simple || (stat(nbuf, &st) == 0 && |
