]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/xundump.c
Make xundump catch extraneous fields
[empserver] / src / lib / common / xundump.c
index a2b3bd42339f4fa6627f221a64baaf07c731a3e6..d1d6f7e8178fd756a3afe39fa64acbfceb26dfb3 100644 (file)
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include "file.h"
 #include "match.h"
 #include "nsc.h"
 #include "optlist.h"
-#include "prototypes.h"
+#include "xdump.h"
 
 static char *fname;            /* Name of file being read */
 static int lineno;             /* Current line number */
@@ -130,21 +132,6 @@ skipfs(FILE *fp)
     return ch;
 }
 
-/*
- * Read an identifier from FP into BUF.
- * BUF must have space for 1024 characters.
- * Return number of characters read on success, -1 on failure.
- */
-static int
-getid(FILE *fp, char *buf)
-{
-    int n;
-    if (fscanf(fp, "%1023[^#()<>=#\" \t\n]%n", buf, &n) != 1
-       || !isalpha(buf[0]))
-       return -1;
-    return n;
-}
-
 /*
  * Decode escape sequences in BUF.
  * Return BUF on success, null pointer on failure.
@@ -170,6 +157,22 @@ xuesc(char *buf)
     return buf;
 }
 
+/*
+ * Read an identifier from FP into BUF.
+ * BUF must have space for 1024 characters.
+ * Return number of characters read on success, -1 on failure.
+ */
+static int
+getid(FILE *fp, char *buf)
+{
+    int n;
+    if (fscanf(fp, "%1023[^\"#()<>= \t\n]%n", buf, &n) != 1
+       || !isalpha(buf[0]))
+       return -1;
+    xuesc(buf);
+    return n;
+}
+
 /*
  * Try to read a field name from FP.
  * I is the field number, counting from zero.
@@ -349,6 +352,8 @@ deffld(int fldno, char *name, int idx)
     if (res < 0)
        return gripe("Header %s of field %d is %s", name, fldno + 1,
                     res == M_NOTUNIQUE ? "ambiguous" : "unknown");
+    if (ca[res].ca_flags == NSC_EXTRA)
+       return gripe("Extraneous header %s in field %d", name, fldno + 1);
     if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
        if (idx < 0)
            return gripe("Header %s requires an index in field %d",