X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fm_getfld.c;h=c085bf5f16bdb5db4c5ad1861fb45bcbeb90ca71;hp=8697f20692e8c5b2f2d5517b24a9cf23c8c182ac;hb=1bb1f6c3f38b05060bf699ea2743f7386889bf63;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 8697f20..c085bf5 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -3,10 +3,15 @@ * m_getfld.c -- read/parse a message * * $Id$ + * + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include -#include +#include +#include /* This module has a long and checkered history. First, it didn't burst maildrops correctly because it considered two CTRL-A:s in a row to be @@ -184,6 +189,7 @@ static int (*eom_action)() = NULL; # define _ptr _p /* Gag */ # define _cnt _r /* Retch */ # define _filbuf __srget /* Puke */ +# define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC #endif #ifdef SCO_5_STDIO @@ -191,6 +197,11 @@ static int (*eom_action)() = NULL; # define _cnt __cnt # define _base __base # define _filbuf(fp) ((fp)->__cnt = 0, __filbuf(fp)) +# define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC +#endif + +#ifndef DEFINED__FILBUF_TO_SOMETHING_SPECIFIC +extern int _filbuf(FILE*); #endif @@ -259,7 +270,7 @@ m_getfld (int state, unsigned char *name, unsigned char *buf, bp = sp = (unsigned char *) iob->_ptr - 1; j = (cnt = iob->_cnt+1) < i ? cnt : i; #endif - while ((c = *bp++) != ':' && c != '\n' && --j >= 0) + while (--j >= 0 && (c = *bp++) != ':' && c != '\n') *cp++ = c; j = bp - sp; @@ -390,7 +401,8 @@ m_getfld (int state, unsigned char *name, unsigned char *buf, *cp++ = j = *(iob->_ptr + c); c = _filbuf(iob); #endif - if ((j == '\0' || j == '\n') && c != ' ' && c != '\t') { + if (c == EOF || + ((j == '\0' || j == '\n') && c != ' ' && c != '\t')) { if (c != EOF) { #ifdef LINUX_STDIO --iob->_IO_read_ptr; @@ -538,7 +550,7 @@ m_unknown(FILE *iob) ; #else /* RPATHS */ cp = unixbuf; - while ((c = getc (iob)) != '\n') + while ((c = getc (iob)) != '\n' && cp - unixbuf < BUFSIZ - 1) *cp++ = c; *cp = 0; #endif /* RPATHS */ @@ -551,7 +563,7 @@ m_unknown(FILE *iob) msg_style = MS_MMDF; } c = strlen (delimstr); - fdelim = (unsigned char *) malloc((size_t) (c + 3)); + fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); *fdelim++ = '\0'; *fdelim = '\n'; msg_delim = (char *)fdelim+1; @@ -571,7 +583,7 @@ m_unknown(FILE *iob) pat_map = (unsigned char **) calloc (256, sizeof(unsigned char *)); for (cp = (char *) fdelim + 1; cp < (char *) delimend; cp++ ) - pat_map[*cp] = (unsigned char *) cp; + pat_map[(unsigned char)*cp] = (unsigned char *) cp; if (msg_style == MS_MMDF) { /* flush extra msg hdrs */ @@ -639,7 +651,7 @@ m_Eom (int c, FILE *iob) break; #else /* RPATHS */ cp = unixbuf; - while ((c = getc (iob)) != '\n' && c >= 0) + while ((c = getc (iob)) != '\n' && c >= 0 && cp - unixbuf < BUFSIZ - 1) *cp++ = c; *cp = 0; #endif /* RPATHS */ @@ -723,7 +735,8 @@ matchc(int patln, char *pat, int strln, char *str) while (pc != *str++) if (str > es) return 0; - + if (str > es+1) + return 0; sp = str; pp = pat; while (pp < ep && *sp++ == *pp) pp++;