X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/9d046ee0503d4c8cbfcb200c88986de876f6cae7..6d3b0e4599c5aa922bba42e53b038b51d9024a62:/print-resp.c diff --git a/print-resp.c b/print-resp.c index 0649c89f..37a386e3 100644 --- a/print-resp.c +++ b/print-resp.c @@ -36,9 +36,6 @@ #include "netdissect-stdinc.h" #include "netdissect.h" #include -#include -#include -#include #include "extract.h" @@ -59,7 +56,6 @@ #define resp_print_length_negative(ndo) ND_PRINT(" length negative and not -1") #define resp_print_invalid(ndo) ND_PRINT(" invalid") -void resp_print(netdissect_options *, const u_char *, u_int); static int resp_parse(netdissect_options *, const u_char *, int); static int resp_print_string_error_integer(netdissect_options *, const u_char *, int); static int resp_print_simple_string(netdissect_options *, const u_char *, int); @@ -89,8 +85,9 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch #define FIND_CRLF(_ptr, _len) \ for (;;) { \ LCHECK2(_len, 2); \ - ND_TCHECK_2(_ptr); \ - if (*_ptr == '\r' && *(_ptr+1) == '\n') \ + ND_TCHECK_2(_ptr); \ + if (GET_U_1(_ptr) == '\r' && \ + GET_U_1(_ptr+1) == '\n') \ break; \ _ptr++; \ _len--; \ @@ -115,8 +112,8 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch #define FIND_CR_OR_LF(_ptr, _len) \ for (;;) { \ LCHECK(_len); \ - ND_TCHECK_1(_ptr); \ - if (*_ptr == '\r' || *_ptr == '\n') \ + if (GET_U_1(_ptr) == '\r' || \ + GET_U_1(_ptr) == '\n') \ break; \ _ptr++; \ _len--; \ @@ -151,7 +148,8 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch */ \ goto trunc; \ } \ - if (*_ptr != '\r' && *_ptr != '\n') \ + if (GET_U_1(_ptr) != '\r' && \ + GET_U_1(_ptr) != '\n') \ break; \ _found_cr_or_lf = 1; \ _ptr++; \ @@ -211,14 +209,12 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch void resp_print(netdissect_options *ndo, const u_char *bp, u_int length) { - int ret_len = 0, length_cur = length; + int ret_len = 0; ndo->ndo_protocol = "resp"; - if(!bp || length <= 0) - return; ND_PRINT(": RESP"); - while (length_cur > 0) { + while (length > 0) { /* * This block supports redis pipelining. * For example, multiple operations can be pipelined within the same string: @@ -228,10 +224,10 @@ resp_print(netdissect_options *ndo, const u_char *bp, u_int length) * In order to handle this case, we must try and parse 'bp' until * 'length' bytes have been processed or we reach a trunc condition. */ - ret_len = resp_parse(ndo, bp, length_cur); + ret_len = resp_parse(ndo, bp, length); TEST_RET_LEN_NORETURN(ret_len); bp += ret_len; - length_cur -= ret_len; + length -= ret_len; } return; @@ -247,7 +243,6 @@ resp_parse(netdissect_options *ndo, const u_char *bp, int length) int ret_len; LCHECK2(length, 1); - ND_TCHECK_1(bp); op = GET_U_1(bp); /* bp now points to the op, so these routines must skip it */ @@ -464,7 +459,6 @@ resp_get_length(netdissect_options *ndo, const u_char *bp, int len, const u_char if (len == 0) goto trunc; - ND_TCHECK_1(bp); too_large = 0; neg = 0; if (GET_U_1(bp) == '-') { @@ -478,7 +472,6 @@ resp_get_length(netdissect_options *ndo, const u_char *bp, int len, const u_char for (;;) { if (len == 0) goto trunc; - ND_TCHECK_1(bp); c = GET_U_1(bp); if (!(c >= '0' && c <= '9')) { if (!saw_digit) { @@ -516,7 +509,6 @@ resp_get_length(netdissect_options *ndo, const u_char *bp, int len, const u_char len--; if (len == 0) goto trunc; - ND_TCHECK_1(bp); if (GET_U_1(bp) != '\n') { bp++; goto invalid;