From 44d6e48c7b13f29f5f80a9308bbcebc4be490db3 Mon Sep 17 00:00:00 2001 From: --global Date: Tue, 3 May 2022 09:33:56 +0200 Subject: [PATCH] Fix conditional jumps based on uninitialized memory at 'process_cmnt_type_1' Solved previously left TODOs, removed faulty logic for whitespace processing for comments using position 'res_cur_pos'. This position shall not be used because points to yet uninitialized memory, last position with copied query data should always be 'res_cur_pos-1'. Because of it, removing the extra logic based on 'res_cur_pos' should be harmless. --- lib/c_tokenizer.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/c_tokenizer.cpp b/lib/c_tokenizer.cpp index 458bace9f..dc405e004 100644 --- a/lib/c_tokenizer.cpp +++ b/lib/c_tokenizer.cpp @@ -1241,7 +1241,6 @@ enum p_st process_cmnt_type_1(options* opts, shared_st* shared_st, cmnt_type_1_s shared_st->res_cur_pos += copy_length; - // TODO: Check if the copy can be prevented as in the outer check for non-cmd comments // The extra space is due to the removal of '*/', this is relevant because the // comment can be in the middle of the query. if (*(shared_st->res_cur_pos - 1 ) != ' ' && shared_st->res_cur_pos != res_final_pos) { @@ -1255,18 +1254,18 @@ enum p_st process_cmnt_type_1(options* opts, shared_st* shared_st, cmnt_type_1_s c_t_1_st->cur_cmd_cmnt_len = 0; } - // TODO: Related to previous TODO. Remember this is a relatively new change in the current code - // not at the beginning and previous char is not ' ' if ( + // not at the beginning or at the end of the query shared_st->res_init_pos != shared_st->res_cur_pos && shared_st->res_cur_pos != res_final_pos && - *shared_st->res_cur_pos != ' ' && *(shared_st->res_cur_pos-1) != ' ' + // if the prev copied char isn't a space comment wasn't space separated in the query: + // ``` + // Q: `SELECT/*FOO*/1` + // ^ no space char + // ``` + // thus we impose an extra space in replace for the ommited comment + *(shared_st->res_cur_pos-1) != ' ' ) { *shared_st->res_cur_pos++ = ' '; - } else if ( - shared_st->res_init_pos != shared_st->res_cur_pos && shared_st->res_cur_pos != res_final_pos && - *shared_st->res_cur_pos == ' ' - ) { - shared_st->res_cur_pos++; } // if there were no space we have imposed it