From 7fbe472c452717e4e5d08cd5905184012d788c0a Mon Sep 17 00:00:00 2001 From: John Denker Date: Sat, 14 Jul 2012 16:19:15 -0700 Subject: implement size-limit --- tools/skrewt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tools/skrewt.c') diff --git a/tools/skrewt.c b/tools/skrewt.c index da0ed64..8ae4db4 100644 --- a/tools/skrewt.c +++ b/tools/skrewt.c @@ -100,12 +100,15 @@ int main(int argc, char** argv){ int text_type(1); int textlines(0); int gotdate(0); + int msgsize(0); + int msgmax(1000000); for (;;){ if (cin.eof()) break; if (cin.bad()) return 1; if (inheads) { string header; if (getline(cin, header).fail()) continue; + msgsize += header.length()+1; for (;;) { if (cin.eof()) break; if (cin.bad()) return 1; @@ -115,6 +118,11 @@ int main(int argc, char** argv){ if (ch != ' ' && ch != '\t') break; string line; if (getline(cin, line).fail()) continue; + msgsize += line.length()+1; + if (msgsize > msgmax) { + cerr << "skrewt rejection: bigger than " << msgmax << endl; + exit(1); + } header += "\n" + line; } if (header.length() == 0) { @@ -176,6 +184,11 @@ int main(int argc, char** argv){ } else { string line; if (!getline(cin, line).fail()) { + msgsize += line.length()+1; + if (msgsize > msgmax) { + cerr << "skrewt rejection: bigger than " << msgmax << endl; + exit(1); + } if (line == "--" + boundary) { inheads = 1; } else { -- cgit v1.2.3