$NetBSD: patch-ac,v 1.2 2000/07/10 18:26:54 tron Exp $ --- sys/bsd/fileio.c.orig Sun Jul 3 10:50:24 1988 +++ sys/bsd/fileio.c Wed May 31 16:38:11 2000 @@ -2,6 +2,9 @@ * bsd (4.2, others?), Sun (3.2, ?) and Ultrix-32 (?) file I/O. */ #include "def.h" +#include /* refling added this per compiler */ +#include +#include static FILE *ffp; extern char *getenv(), *strncpy(); @@ -11,6 +14,12 @@ * Open a file for reading. */ ffropen(fn) char *fn; { + // prevent opening non-regular files - refling + struct stat st; + if (fn == NULL || 0 == strlen(fn) || (0 == stat(fn, &st) && ((st.st_mode & S_IFMT) != S_IFREG))) { + ewprintf("not a regular file"); + return(FIOERR); + } if ((ffp=fopen(fn, "r")) == NULL) return (FIOFNF); return (FIOSUC); @@ -22,6 +31,12 @@ * FALSE on error (cannot create). */ ffwopen(fn) char *fn; { + // prevent opening non-regular files - refling + struct stat st; + if (fn == NULL || 0 == strlen(fn) || (0 == stat(fn, &st) && ((st.st_mode & S_IFMT) != S_IFREG))) { + ewprintf("not a regular file"); + return(FIOERR); + } if ((ffp=fopen(fn, "w")) == NULL) { ewprintf("Cannot open file for writing"); return (FIOERR); @@ -276,7 +291,7 @@ if ((file = getenv("HOME")) == NULL) goto notfound; if (strlen(file)+7 >= NFILEN - 1) goto notfound; (VOID) strcpy(home, file); - (VOID) strcat(home, "/.mg"); + (VOID) strcat(home, "/.mgrc"); if (suffix != NULL) { (VOID) strcat(home, "-"); (VOID) strcat(home, suffix); @@ -295,6 +310,18 @@ if (access(file, F_OK ) == 0) return file; #endif + +/* refling - try to open a file name given by MGRC env var */ + if ((file = getenv("MGRC")) == NULL) return NULL; + if (strlen(file)+7 >= NFILEN - 1) goto notfound; + (VOID) strcpy(home, file); + if (suffix != NULL) { + (VOID) strcat(home, "-"); + (VOID) strcat(home, suffix); + } + if (access(home, F_OK ) == 0) return home; + + return NULL; } #endif @@ -318,7 +345,8 @@ execve("cp", eargv, (char **)NULL); _exit(1); /* shouldn't happen */ } - while(wait(&status) != pid) {} +/* while(wait(&status) != pid) {} refling, was this */ + while(wait((int *)&status) != pid) {} return status.w_status == 0; }