tVerify headers before processing content - scribo - Email-based phlog generator
HTML git clone git://git.z3bra.org/scribo.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 6d46f8051a81903f4c47f459a2bee9cd79ef7048
DIR parent 3e2b42bb700a97dd976731361c87fb4299682091
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Tue, 8 Sep 2020 13:57:54 +0200
Verify headers before processing content
Diffstat:
M scribo.c | 34 +++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)
---
DIR diff --git a/scribo.c b/scribo.c
t@@ -36,6 +36,7 @@ char * sanitize(const char *);
char * header(struct headers *, char *);
struct hdr * saveheader(struct headers *, char *);
int parseheaders(FILE *, struct headers *);
+int verifyheaders(struct headers *);
int writeentry(FILE *, char *, struct headers *);
int writeindex(FILE *, char *);
t@@ -128,6 +129,36 @@ parseheaders(FILE *fp, struct headers *head)
}
int
+verifyheaders(struct headers *head)
+{
+ if (!head)
+ return -1;
+
+ if (!header(head, "Date")) {
+ fprintf(stderr, "Missing header: Date\n");
+ return -1;
+ }
+
+ if (!header(head, "Subject")) {
+ fprintf(stderr, "Missing header: Subject\n");
+ return -1;
+ }
+
+ if (!header(head, "Content-Type")) {
+ fprintf(stderr, "Missing header: Content-Type\n");
+ return -1;
+ }
+
+ /* only accept plain text emails */
+ if (strncmp(header(head, "Content-Type"), "text/plain", 10)) {
+ fprintf(stderr, "Invalid Content-Type: %s\n", header(head, "Content-Type"));
+ return -1;
+ }
+
+ return 0;
+}
+
+int
writeentry(FILE *in, char *dir, struct headers *head)
{
FILE *out;
t@@ -231,6 +262,9 @@ main(int argc, char *argv[])
return -1;
}
+ if (verifyheaders(&headers) < 0)
+ return -1;
+
if (writeentry(in, basedir, &headers) < 0) {
perror("header section");
return -1;