# HG changeset patch # User Mike Becker # Date 1432815332 -7200 # Node ID 5ffc2f23803fcbe1731a0f41efde296a192f72e1 # Parent 44ffe073b5e30271aa1cf6048aa14378fc32d990 fixed null pointer access on end of token stream by adding a special END token to the stream diff -r 44ffe073b5e3 -r 5ffc2f23803f libidav/davqlparser.c --- 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); } diff -r 44ffe073b5e3 -r 5ffc2f23803f libidav/davqlparser.h --- 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; /**