aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-10-18 06:34:16 +0200
committerPřemysl Janouch <p@janouch.name>2018-10-18 06:34:16 +0200
commitbca7167d037d857448cb18243425d7c61de3bdd5 (patch)
tree1e93b857b0b9a996211245b434a80ebb01f9125d
parent3e4e4e5103b10e0cfada77489370e5a938a60f70 (diff)
downloadliberty-bca7167d037d857448cb18243425d7c61de3bdd5.tar.gz
liberty-bca7167d037d857448cb18243425d7c61de3bdd5.tar.xz
liberty-bca7167d037d857448cb18243425d7c61de3bdd5.zip
Fix the SCGI parser and tests
-rw-r--r--liberty-proto.c5
-rw-r--r--tests/proto.c31
2 files changed, 27 insertions, 9 deletions
diff --git a/liberty-proto.c b/liberty-proto.c
index fa6ab76..018523f 100644
--- a/liberty-proto.c
+++ b/liberty-proto.c
@@ -664,10 +664,11 @@ scgi_parser_push (struct scgi_parser *self,
if (digit == ':')
{
self->state = SCGI_READING_NAME;
+ str_remove_slice (&self->input, 0, 1);
break;
}
- if (digit < '0' || digit >= '9')
+ if (digit < '0' || digit > '9')
return error_set (e, "invalid header netstring");
size_t new_len = self->headers_len * 10 + (digit - '0');
@@ -700,6 +701,7 @@ scgi_parser_push (struct scgi_parser *self,
self->state = SCGI_READING_VALUE;
str_remove_slice (&self->input, 0, 1);
+ self->headers_len--;
break;
}
case SCGI_READING_VALUE:
@@ -728,6 +730,7 @@ scgi_parser_push (struct scgi_parser *self,
}
str_remove_slice (&self->input, 0, 1);
+ self->headers_len--;
break;
}
case SCGI_READING_CONTENT:
diff --git a/tests/proto.c b/tests/proto.c
index 2b69e2f..3bcfbf9 100644
--- a/tests/proto.c
+++ b/tests/proto.c
@@ -105,10 +105,20 @@ test_http_parser (void)
http_protocol_destroy (iter);
}
+struct scgi_fixture
+{
+ struct scgi_parser parser;
+ bool seen_headers;
+ bool seen_content;
+};
+
static bool
test_scgi_parser_on_headers_read (void *user_data)
{
- struct scgi_parser *parser = user_data;
+ struct scgi_fixture *fixture = user_data;
+ struct scgi_parser *parser = &fixture->parser;
+ fixture->seen_headers = true;
+
soft_assert (parser->headers.len == 4);
soft_assert (!strcmp (str_map_find (&parser->headers,
"CONTENT_LENGTH"), "27"));
@@ -124,7 +134,9 @@ test_scgi_parser_on_headers_read (void *user_data)
static bool
test_scgi_parser_on_content (void *user_data, const void *data, size_t len)
{
- (void) user_data;
+ struct scgi_fixture *fixture = user_data;
+ fixture->seen_content = true;
+
soft_assert (!strncmp (data, "What is the answer to life?", len));
return true;
}
@@ -132,10 +144,12 @@ test_scgi_parser_on_content (void *user_data, const void *data, size_t len)
static void
test_scgi_parser (void)
{
- struct scgi_parser parser = scgi_parser_make ();
- parser.on_headers_read = test_scgi_parser_on_headers_read;
- parser.on_content = test_scgi_parser_on_content;
- parser.user_data = &parser;
+ struct scgi_fixture fixture = { scgi_parser_make(), false, false };
+ struct scgi_parser *parser = &fixture.parser;
+
+ parser->on_headers_read = test_scgi_parser_on_headers_read;
+ parser->on_content = test_scgi_parser_on_content;
+ parser->user_data = &fixture;
// This is an example straight from the specification
const char example[] =
@@ -147,8 +161,9 @@ test_scgi_parser (void)
","
"What is the answer to life?";
- soft_assert (scgi_parser_push (&parser, example, sizeof example, NULL));
- scgi_parser_free (&parser);
+ soft_assert (scgi_parser_push (parser, example, sizeof example, NULL));
+ soft_assert (fixture.seen_headers && fixture.seen_content);
+ scgi_parser_free (parser);
}
static bool