clickhouse-odbc icon indicating copy to clipboard operation
clickhouse-odbc copied to clipboard

driver/test/statement_parameters_it.cpp: buffer not null terminated (found by Coverity)

Open chipitsine opened this issue 6 years ago • 1 comments

285        char * param_ptr = reinterpret_cast<char *>(param);
   CID 1408171 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)1. buffer_size_warning: Calling strncpy with a maximum size argument of 256 bytes on destination array param_ptr of size 256 bytes might leave the destination string unterminated.
286        std::strncpy(param_ptr, initial_str.c_str(), lengthof(param));
287
288        // We need this to autodetect actual precision and scale of the value in initial_str.
289        auto param_typed = value_manip::to<SQL_NUMERIC_STRUCT>::template from<std::string>(initial_str);

chipitsine avatar Dec 01 '19 20:12 chipitsine

Thanks for the find.

Going to change those lines to this:

        char * param_ptr = reinterpret_cast<char *>(param);
        ASSERT_LT(initial_str.size(), lengthof(param));
        std::strncpy(param_ptr, initial_str.c_str(), lengthof(param) - 1);

traceon avatar Dec 01 '19 21:12 traceon