chip@ateng.ateng.com (Chip Salzenberg) (11/29/88)
This is an offical patch for deliver 1.00. Please apply it. Patch number: 4 Date: 28 Nov 1988 Priority: MEDIUM-RARE Changes: Add return type of signal handlers to config.h. Provide a version of getopt() for systems that lack it. Call va_end() in routines that use varargs. Make consistent checks for valid address strings. Index: patchlevel.h Prereq: 3 *************** *** 1 **** ! #define PATCHLEVEL 3 --- 1 ---- ! #define PATCHLEVEL 4 Index: config.h *************** *** 1,8 **** ! /* $Header: config.h,v 1.5 88/11/21 13:12:11 network Exp $ * * Deliver configuration. * * $Log: config.h,v $ * Revision 1.5 88/11/21 13:12:11 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. --- 1,14 ---- ! /* $Header: config.h,v 1.6 88/11/26 13:19:37 network Exp $ * * Deliver configuration. * * $Log: config.h,v $ + * Revision 1.6 88/11/26 13:19:37 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.5 88/11/21 13:12:11 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. *************** *** 36,41 **** --- 42,55 ---- #define TRUSTED_USERS "root", "uucp" /*---------------------------------------------------------------------- + * Signal function type. + * Signal catching routines have this return value. + * (For System V Release 3.0 or later, use "void".) + */ + + #define SIGTYPE int + + /*---------------------------------------------------------------------- * Signal flag type. * Variables of this type may be set by signal catching routines. */ *************** *** 103,120 **** /*---------------------------------------------------------------------- * Are vprintf() and friends available? - * Is putenv() available? */ #ifndef BSD #define HAS_VPRINTF #define HAS_PUTENV #endif /*---------------------------------------------------------------------- ! * Is setvbuf() backwards? (Blech!) */ #ifdef M_XENIX #define XENIX_SETVBUF #endif --- 117,148 ---- /*---------------------------------------------------------------------- * Are vprintf() and friends available? */ #ifndef BSD #define HAS_VPRINTF + #endif + + /*---------------------------------------------------------------------- + * Is putenv() available? + */ + + #ifndef BSD #define HAS_PUTENV #endif /*---------------------------------------------------------------------- ! * Is getopt() available? */ + #ifndef BSD + #define HAS_GETOPT + #endif + + /*---------------------------------------------------------------------- + * Is setvbuf() backwards? + */ + #ifdef M_XENIX #define XENIX_SETVBUF #endif *************** *** 124,129 **** --- 152,164 ---- */ #define SHELL "/bin/sh" + + /*---------------------------------------------------------------------- + * Characters that may not appear in addresses. + * (This string should include all metacharacters for your chosen shell.) + */ + + #define SANITIZE "$*?=\\`'\"|^&;{}()<>" /*---------------------------------------------------------------------- * Standard mailbox location. Index: debug.c *************** *** 1,8 **** ! /* $Header: debug.c,v 1.1 88/06/06 09:38:23 chip Exp $ * * Debugging output. * * $Log: debug.c,v $ * Revision 1.1 88/06/06 09:38:23 chip * Initial revision * --- 1,14 ---- ! /* $Header: debug.c,v 1.2 88/11/26 13:20:38 network Exp $ * * Debugging output. * * $Log: debug.c,v $ + * Revision 1.2 88/11/26 13:20:38 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.1 88/06/06 09:38:23 chip * Initial revision * *************** *** 23,45 **** for (d = first_dest(); d; d = next_dest(d)) { message("\t%s", d->name); - if (d->class == CL_MBOX) - message(":%s", d->mailbox); - message(" ("); switch (d->class) { case CL_USER: ! message("User"); break; case CL_MBOX: ! message("Mailbox"); break; case CL_UUCP: ! message("UUCP"); break; } ! message(", "); switch (d->state) { case ST_WORKING: --- 29,48 ---- for (d = first_dest(); d; d = next_dest(d)) { message("\t%s", d->name); switch (d->class) { case CL_USER: ! /* it's understood */ break; case CL_MBOX: ! message(", mailbox='%s'", d->mailbox); break; case CL_UUCP: ! message(" (UUCP)"); break; } ! message("; "); switch (d->state) { case ST_WORKING: *************** *** 52,60 **** message("Done"); break; case ST_ERROR: ! message("Error: %s", d->error); break; } ! message(")\n"); } } --- 55,63 ---- message("Done"); break; case ST_ERROR: ! message("Error (%s)", d->error); break; } ! message("\n"); } } Index: dest.c *************** *** 1,8 **** ! /* $Header: dest.c,v 1.2 88/08/30 16:12:40 network Exp $ * * Operations on the list of mail destinations. * * $Log: dest.c,v $ * Revision 1.2 88/08/30 16:12:40 network * Use savestr() instead of strdup(). * --- 1,14 ---- ! /* $Header: dest.c,v 1.3 88/11/26 13:20:42 network Exp $ * * Operations on the list of mail destinations. * * $Log: dest.c,v $ + * Revision 1.3 88/11/26 13:20:42 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.2 88/08/30 16:12:40 network * Use savestr() instead of strdup(). * *************** *** 75,86 **** if (class == CL_MBOX) d->mailbox = copystr(mailbox); ! if (class != CL_UUCP && name_context(name) == NULL) { d->state = ST_ERROR; d->error = "No such user"; } d->prev = HEADPTR->prev; d->next = HEADPTR; --- 81,106 ---- if (class == CL_MBOX) d->mailbox = copystr(mailbox); ! /* ! * Check address for validity. ! */ ! ! if (!valid_address(name)) ! { ! d->state = ST_ERROR; ! d->error = "Invalid address string"; ! } ! else if (class != CL_UUCP && name_context(name) == NULL) { d->state = ST_ERROR; d->error = "No such user"; } + + /* + * Put new address at the end of of the chain. + * (This is important! Other code depends on it.) + */ d->prev = HEADPTR->prev; d->next = HEADPTR; Index: dfile.c *************** *** 1,8 **** ! /* $Header: dfile.c,v 1.4 88/11/21 13:12:19 network Exp $ * * Filter destination(s) through delivery file(s). * * $Log: dfile.c,v $ * Revision 1.4 88/11/21 13:12:19 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. --- 1,14 ---- ! /* $Header: dfile.c,v 1.5 88/11/26 13:20:45 network Exp $ * * Filter destination(s) through delivery file(s). * * $Log: dfile.c,v $ + * Revision 1.5 88/11/26 13:20:45 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.4 88/11/21 13:12:19 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. *************** *** 72,99 **** goodnames = 0; for (a = 0; a < dac; ++a) { ! char *p; ! for (p = dav[a]; *p; ++p) { ! if (!isalpha(*p) ! && !isdigit(*p) ! && !strchr("#%-+._", *p)) ! break; ! } ! if (*p) ! { ! /* Invalid name -- note it and go on. */ ! ! (void) dest(dav[a], (char *) NULL); } else { ! /* Valid name -- let the delivery file handle it. */ ! fav[fac++] = dav[a]; ! ++goodnames; } } --- 78,98 ---- goodnames = 0; for (a = 0; a < dac; ++a) { ! char *addr; ! addr = dav[a]; ! if (valid_address(addr)) { ! /* Let the delivery file handle valid addresses. */ ! fav[fac++] = addr; ! ++goodnames; } else { ! /* Note invalid address(es); report them later. */ ! (void) dest(addr, (char *) NULL); } } Index: main.c *************** *** 1,8 **** ! /* $Header: main.c,v 1.7 88/11/18 12:17:17 network Exp $ * * A program to deliver local mail with some flexibility. * * $Log: main.c,v $ * Revision 1.7 88/11/18 12:17:17 network * patch2: Improved signal handling. * patch2: Make sure all environment variables are always provided. --- 1,14 ---- ! /* $Header: main.c,v 1.8 88/11/26 13:20:51 network Exp $ * * A program to deliver local mail with some flexibility. * * $Log: main.c,v $ + * Revision 1.8 88/11/26 13:20:51 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.7 88/11/18 12:17:17 network * patch2: Improved signal handling. * patch2: Make sure all environment variables are always provided. *************** *** 94,100 **** * Local functions. */ ! static int sighup(), sigint(), sigquit(); /*---------------------------------------------------------------------- * The Program. --- 100,106 ---- * Local functions. */ ! static SIGTYPE sighup(), sigint(), sigquit(); /*---------------------------------------------------------------------- * The Program. *************** *** 503,509 **** (void) signal(SIGQUIT, SIG_IGN); } ! static int sighup() { (void) signal(SIGHUP, sighup); --- 509,515 ---- (void) signal(SIGQUIT, SIG_IGN); } ! static SIGTYPE sighup() { (void) signal(SIGHUP, sighup); *************** *** 510,516 **** got_sig = TRUE; } ! static int sigint() { (void) signal(SIGINT, sigint); --- 516,522 ---- got_sig = TRUE; } ! static SIGTYPE sigint() { (void) signal(SIGINT, sigint); *************** *** 517,523 **** got_sig = TRUE; } ! static int sigquit() { (void) signal(SIGQUIT, sigquit); --- 523,529 ---- got_sig = TRUE; } ! static SIGTYPE sigquit() { (void) signal(SIGQUIT, sigquit); *************** *** 547,553 **** hostname); } ! message("\tuser \"%s\"", d->name); if (d->class == CL_MBOX) message(", mailbox \"%s\"", d->mailbox); message(": %s\n", d->error); --- 553,559 ---- hostname); } ! message("\t\"%s\"", d->name); if (d->class == CL_MBOX) message(", mailbox \"%s\"", d->mailbox); message(": %s\n", d->error); Index: misc.h *************** *** 1,8 **** ! /* $Header: misc.h,v 1.3 88/11/21 13:12:29 network Exp $ * * Miscellaneous definitions. * * $Log: misc.h,v $ * Revision 1.3 88/11/21 13:12:29 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. --- 1,14 ---- ! /* $Header: misc.h,v 1.4 88/11/26 13:21:01 network Exp $ * * Miscellaneous definitions. * * $Log: misc.h,v $ + * Revision 1.4 88/11/26 13:21:01 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.3 88/11/21 13:12:29 network * patch3: Fix Makefile for GNU Make. * patch3: Remove hard-coded shell name. *************** *** 67,72 **** --- 73,79 ---- extern long lseek(); extern long time(); extern void free(); + extern SIGTYPE (*signal())(); /* * Library differences Index: procs.c *************** *** 1,8 **** ! /* $Header: procs.c,v 1.2 88/09/14 19:42:28 network Exp $ * * Process management and misc support. * * $Log: procs.c,v $ * Revision 1.2 88/09/14 19:42:28 network * Portability to System V and BSD. * General fixup. --- 1,14 ---- ! /* $Header: procs.c,v 1.3 88/11/26 13:21:07 network Exp $ * * Process management and misc support. * * $Log: procs.c,v $ + * Revision 1.3 88/11/26 13:21:07 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.2 88/09/14 19:42:28 network * Portability to System V and BSD. * General fixup. *************** *** 27,33 **** */ static int child_pid = -1; ! static int (*saved_sigpipe)() = SIG_DFL; /*---------------------------------------------------------------------- * Like popen(), but execute the child in a specific context. --- 33,39 ---- */ static int child_pid = -1; ! static SIGTYPE (*saved_sigpipe)() = SIG_DFL; /*---------------------------------------------------------------------- * Like popen(), but execute the child in a specific context. Index: subs.c *************** *** 1,8 **** ! /* $Header: subs.c,v 1.4 88/10/13 12:20:34 network Exp $ * * Miscellaneous subroutines. * * $Log: subs.c,v $ * Revision 1.4 88/10/13 12:20:34 network * patch1: add "-n" option, and general bug fixes. * --- 1,14 ---- ! /* $Header: subs.c,v 1.5 88/11/26 13:21:11 network Exp $ * * Miscellaneous subroutines. * * $Log: subs.c,v $ + * Revision 1.5 88/11/26 13:21:11 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.4 88/10/13 12:20:34 network * patch1: add "-n" option, and general bug fixes. * *************** *** 117,120 **** --- 123,145 ---- b = name; return (b); + } + + /*---------------------------------------------------------------------- + * Check an address for validity. + */ + + valid_address(addr) + char *addr; + { + char *p; + static char sanitize[] = SANITIZE; + + for (p = addr; *p; ++p) + { + if (strchr(sanitize, *p)) + return FALSE; + } + + return TRUE; } Index: sysdep.c *************** *** 1,4 **** ! /* $Header: sysdep.c,v 1.4 88/10/13 12:20:39 network Exp $ * * Routines which are (or might well be) system-dependant. * I've put the message routines here since you may need to use --- 1,4 ---- ! /* $Header: sysdep.c,v 1.5 88/11/26 13:21:15 network Exp $ * * Routines which are (or might well be) system-dependant. * I've put the message routines here since you may need to use *************** *** 5,10 **** --- 5,16 ---- * the ANSI <stdarg.h> instead of <varargs.h>. * * $Log: sysdep.c,v $ + * Revision 1.5 88/11/26 13:21:15 network + * patch4: Add return type of signal handlers to config.h. + * patch4: Provide a version of getopt() for systems that lack it. + * patch4: Call va_end() in routines that use varargs. + * patch4: Make consistent checks for valid address strings. + * * Revision 1.4 88/10/13 12:20:39 network * patch1: add "-n" option, and general bug fixes. * *************** *** 59,64 **** --- 65,72 ---- va_start(args); (void) vfprintf(stderr, fmt, args); + + va_end(args); } /*---------------------------------------------------------------------- *************** *** 75,80 **** --- 83,90 ---- (void) fprintf(stderr, "%s: ", progname); (void) vfprintf(stderr, fmt, args); + + va_end(args); } /*---------------------------------------------------------------------- *************** *** 96,101 **** --- 106,113 ---- (void) fprintf(stderr, ": %s\n", sys_errlist[e]); else (void) fprintf(stderr, ": unknown system error %d\n", e); + + va_end(args); } /*---------------------------------------------------------------------- *************** *** 239,245 **** (void) sprintf(s, fmt, a,b,c,d,e,f,g,h); } ! #endif /* HAS_VPRINTF */ /*---------------------------------------------------------------------- * Add a new environment variable. --- 251,257 ---- (void) sprintf(s, fmt, a,b,c,d,e,f,g,h); } ! #endif /* !HAS_VPRINTF */ /*---------------------------------------------------------------------- * Add a new environment variable. *************** *** 295,298 **** return 0; } ! #endif /* HAS_PUTENV */ --- 307,392 ---- return 0; } ! #endif /* !HAS_PUTENV */ ! ! /*---------------------------------------------------------------------- ! * Get command line options. ! * This is essentially the public domain version, reformatted to ! * my style and using my error message routine. ! */ ! ! #ifndef HAS_GETOPT ! ! int opterr = 1; ! int optind = 1; ! int optopt = 0; ! char *optarg = NULL; ! ! int ! getopt(argc, argv, opts) ! int argc; ! char **argv; ! char *opts; ! { ! static int sp = 1; ! int c; ! char *cp; ! ! if (sp == 1) ! { ! if (optind >= argc ! || argv[optind][0] != '-' || argv[optind][1] == '\0') ! return EOF; ! ! if (strcmp(argv[optind], "--") == NULL) ! { ! optind++; ! return EOF; ! } ! } ! ! optopt = c = argv[optind][sp]; ! ! if (c == ':' || (cp = strchr(opts, c)) == NULL) ! { ! if (opterr) ! error("illegal option -- %c\n", c); ! if (argv[optind][++sp] == '\0') ! { ! optind++; ! sp = 1; ! } ! return '?'; ! } ! ! if (*++cp == ':') ! { ! if (argv[optind][sp + 1] != '\0') ! optarg = &argv[optind++][sp + 1]; ! else if (++optind >= argc) ! { ! if (opterr) ! error("option requires an argument -- %c\n", c); ! sp = 1; ! return '?'; ! } ! else ! optarg = argv[optind++]; ! ! sp = 1; ! } ! else ! { ! if (argv[optind][++sp] == '\0') ! { ! sp = 1; ! optind++; ! } ! ! optarg = NULL; ! } ! ! return c; ! } ! ! #endif /* !HAS_GETOPT */ -- Chip Salzenberg <chip@ateng.com> or <uunet!ateng!chip> A T Engineering Me? Speak for my company? Surely you jest! Beware of programmers carrying screwdrivers.