Thu, 28 May 2015 14:15:32 +0200
fixed null pointer access on end of token stream by adding a special END token to the stream
libidav/davqlparser.c | file | annotate | diff | comparison | revisions | |
libidav/davqlparser.h | file | annotate | diff | comparison | revisions |
--- a/libidav/davqlparser.c Thu May 28 13:48:39 2015 +0200 +++ b/libidav/davqlparser.c Thu May 28 14:15:32 2015 +0200 @@ -556,7 +556,10 @@ tokens = dav_parse_add_token(tokens, token); } - return tokens; + DavQLToken *endtoken = malloc(sizeof(DavQLToken)); + endtoken->tokenclass = DAVQL_TOKEN_END; + endtoken->value = S(""); + return ucx_list_append(tokens, endtoken); } static void dav_free_expression(DavQLExpression *expr) { @@ -1357,7 +1360,8 @@ && tokenvalue_is(tokens, "/")) { stmt->path.ptr = token_sstr(tokens).ptr; tokens = tokens->next; - while (!token_is(tokens, DAVQL_TOKEN_KEYWORD)) { + while (!token_is(tokens, DAVQL_TOKEN_KEYWORD) && + !token_is(tokens, DAVQL_TOKEN_END)) { sstr_t toksstr = token_sstr(tokens); stmt->path.length = toksstr.ptr-stmt->path.ptr+toksstr.length; tokens = tokens->next; @@ -1418,7 +1422,7 @@ if (token_is(tokens, DAVQL_TOKEN_INVALID)) { dav_error_in_context(DAVQL_ERROR_INVALID_TOKEN, _error_invalid_token, stmt, tokens); - } else { + } else if (!token_is(tokens, DAVQL_TOKEN_END)) { dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN, _error_unexpected_token, stmt, tokens); }
--- a/libidav/davqlparser.h Thu May 28 13:48:39 2015 +0200 +++ b/libidav/davqlparser.h Thu May 28 14:15:32 2015 +0200 @@ -50,7 +50,7 @@ DAVQL_TOKEN_IDENTIFIER, DAVQL_TOKEN_FMTSPEC, DAVQL_TOKEN_STRING, DAVQL_TOKEN_NUMBER, DAVQL_TOKEN_TIMESTAMP, DAVQL_TOKEN_COMMA, DAVQL_TOKEN_OPENP, DAVQL_TOKEN_CLOSEP, - DAVQL_TOKEN_OPERATOR + DAVQL_TOKEN_OPERATOR, DAVQL_TOKEN_END } davqltokenclass_t; /**