diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-05-30 21:08:16 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-05-30 21:08:16 +0200 |
commit | 9a3629921b250e7079be9abb5252381025c33354 (patch) | |
tree | efba39ef18c690566e2bff423a1125d871d0e1f8 | |
parent | 30c3bd35de3b7c0f5dc22259fdef9194f10f74a4 (diff) | |
download | blogc-9a3629921b250e7079be9abb5252381025c33354.tar.gz blogc-9a3629921b250e7079be9abb5252381025c33354.tar.bz2 blogc-9a3629921b250e7079be9abb5252381025c33354.zip |
git-receiver: pre-receive parser should accept len
-rw-r--r-- | src/blogc-git-receiver/pre-receive-parser.c | 4 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive-parser.h | 4 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive.c | 2 | ||||
-rw-r--r-- | tests/blogc-git-receiver/check_pre_receive_parser.c | 28 |
4 files changed, 21 insertions, 17 deletions
diff --git a/src/blogc-git-receiver/pre-receive-parser.c b/src/blogc-git-receiver/pre-receive-parser.c index fb4c4d5..a5d1e8d 100644 --- a/src/blogc-git-receiver/pre-receive-parser.c +++ b/src/blogc-git-receiver/pre-receive-parser.c @@ -6,6 +6,7 @@ * See the file LICENSE. */ +#include <stddef.h> #include <stdlib.h> #include <string.h> #include "../common/utils.h" @@ -22,12 +23,11 @@ typedef enum { char* -bgr_pre_receive_parse(const char *input) +bgr_pre_receive_parse(const char *input, size_t input_len) { input_state_t state = START_OLD; size_t start = 0; size_t start_new = 0; - size_t input_len = strlen(input); for (size_t current = 0; current < input_len; current++) { diff --git a/src/blogc-git-receiver/pre-receive-parser.h b/src/blogc-git-receiver/pre-receive-parser.h index 7a011a7..e5a392a 100644 --- a/src/blogc-git-receiver/pre-receive-parser.h +++ b/src/blogc-git-receiver/pre-receive-parser.h @@ -9,6 +9,8 @@ #ifndef _PRE_RECEIVE_PARSER_H #define _PRE_RECEIVE_PARSER_H -char* bgr_pre_receive_parse(const char *input); +#include <stddef.h> + +char* bgr_pre_receive_parse(const char *input, size_t input_len); #endif /* _PRE_RECEIVE_PARSER_H */ diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c index 107459e..76cf1bf 100644 --- a/src/blogc-git-receiver/pre-receive.c +++ b/src/blogc-git-receiver/pre-receive.c @@ -171,7 +171,7 @@ default_sym: } else { char *input = bc_stdin_read(); - master = bgr_pre_receive_parse(input); + master = bgr_pre_receive_parse(input, strlen(input)); free(input); } diff --git a/tests/blogc-git-receiver/check_pre_receive_parser.c b/tests/blogc-git-receiver/check_pre_receive_parser.c index 68175f2..37c9486 100644 --- a/tests/blogc-git-receiver/check_pre_receive_parser.c +++ b/tests/blogc-git-receiver/check_pre_receive_parser.c @@ -13,46 +13,48 @@ #include <stdlib.h> #include "../../src/blogc-git-receiver/pre-receive-parser.h" +#define _bgr_pre_receive_parse(a) bgr_pre_receive_parse(a, strlen(a)) + static void test_pre_receive_parse(void **state) { - assert_null(bgr_pre_receive_parse("")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse("")); + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 ")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 ")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 " "refs/heads/lol")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 " "refs/heads/lol")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 " "refs/heads/master")); - assert_null(bgr_pre_receive_parse( + assert_null(_bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 " "refs/heads/master asd\n")); char *t; - t = bgr_pre_receive_parse( + t = _bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545f3 " "refs/heads/master\n"); assert_non_null(t); assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545f3"); free(t); - t = bgr_pre_receive_parse( + t = _bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a62 " "3fff4bb3172f77b292b0c913749e81bedd3545fa " "refs/heads/master\n" @@ -63,7 +65,7 @@ test_pre_receive_parse(void **state) assert_non_null(t); assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545fa"); free(t); - t = bgr_pre_receive_parse( + t = _bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a63 " "3fff4bb3172f77b292b0c913749e81bedd3545f4 " "refs/heads/bola\n" @@ -74,7 +76,7 @@ test_pre_receive_parse(void **state) assert_non_null(t); assert_string_equal(t, "3fff4bb3172f77b292b0c913749e81bedd3545fb"); free(t); - t = bgr_pre_receive_parse( + t = _bgr_pre_receive_parse( "4f1f932f6ef6d6c9770266775c2db072964d7a63 " "3fff4bb3172f77b292b0c913749e81bedd3545f4 " "refs/heads/bola\n" |