check for crlf in m_getfld2
[mmh] / sbr / m_getfld2.c
index 45172aa..b9a618d 100644 (file)
@@ -62,7 +62,8 @@ m_getfld2(enum state s, struct field *f, FILE *msg)
                        }
                }
 
-               if (nchars >= NAMESZ) {
+               f->crlf = (nchars > 2 && tmpline[nchars-2] == '\r');
+               if (nchars > NAMESZ+1 || (!f->crlf && nchars > NAMESZ)) {
                        ret = LENERR2;
                }
 
@@ -96,14 +97,14 @@ m_getfld2(enum state s, struct field *f, FILE *msg)
                        f->valuelen = nchars;
                }
 
-               while (ret == FLD2 && (falted = is_falted(msg)) == B_TRUE) {
+               while ((ret == FLD2 || ret == LENERR2) && (falted = is_falted(msg)) == B_TRUE) {
                        nchars = getline(&tmpline, &len, msg);
                        if (nchars <= 0) {
                                free(tmpline);
                                return IOERR2;
                        }
 
-                       if (nchars >= NAMESZ) {
+                       if (nchars > NAMESZ+1 || (!f->crlf && nchars > NAMESZ)) {
                                ret = LENERR2;
                        }
 
@@ -145,10 +146,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg)
                        }
                }
 
-               if (nchars >= NAMESZ) {
-                       ret = LENERR2;
-               }
-
+               f->crlf = (nchars > 2 && tmpline[nchars-2] == '\r');
                free(f->value);
                f->value = tmpline;
                f->valuelen = nchars;