Skip to content

Fix warnings from CodeQL#12138

Merged
alexey-milovidov merged 5 commits intomasterfrom
codeql
Jul 5, 2020
Merged

Fix warnings from CodeQL#12138
alexey-milovidov merged 5 commits intomasterfrom
codeql

Conversation

@alexey-milovidov
Copy link
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix warnings from CodeQL. CodeQL is another static analyzer that we will use along with clang-tidy and PVS-Studio that we use already.

inline std::string to_string(const std::time_t & time)
{
std::stringstream ss;
ss << std::put_time(std::localtime(&time), "%Y-%m-%d %X");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is real issue. The localtime function cannot be used in multithreaded code. And also this function is extremely slow. @akuzm

But if we have no reports from TSan then it's happened to be not used concurrently.

@blinkov blinkov added the pr-build Pull request with build/testing/packaging improvement label Jul 4, 2020
const auto & weights = static_cast<const ColVecType &>(*columns[1]);

this->data(place).numerator += values.getData()[row_num] * weights.getData()[row_num];
this->data(place).numerator += static_cast<typename Data::NumeratorType>(values.getData()[row_num]) * weights.getData()[row_num];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% bug, thanks to CodeQL.
And it's easily exploitable:

SELECT avgWeighted(x, y) FROM (SELECT 0xFFFFFFFF AS x, 1000000000 AS y UNION ALL SELECT 1 AS x, 1 AS y)

auto proxy_port = proxy_resolver_config.getUInt(prefix + ".proxy_port");

LOG_DEBUG(&Poco::Logger::get("DiskS3"), "Configured proxy resolver: {}, Scheme: {}, Port: {}", endpoint.toString(), proxy_scheme, proxy_port);
LOG_DEBUG(&Poco::Logger::get("DiskS3"), "Configured proxy resolver: {}, Scheme: {}, Port: {}",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-significant change.

result.fill(0);

const auto bits = (precision * BITS_PER_SYMBOL) / 2;
assert(bits <= 255);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to guide static analyzer. Actually it shouldn't overflow with the given range of precision.

return;

cells.assign(grid_size * grid_size, {});
cells.assign(size_t(grid_size) * grid_size, {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exploitable because it cannot overflow with our grid size.
We use 16x16 grid, and this arithmetic is Ok up to 256x256 grid.

{
res[i] = x * (offsets[i] - pos);
/// Just multiply the value by array size.
res[i] = Result(x) * (offsets[i] - pos);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's non-realistic that overflow here will alter the result.
The cases like

SELECT arraySum(x -> toInt32(0x80000000), [1, 2])
and
SELECT arraySum(x -> toFloat32(1000000.1), [1, 2])
work correct.

@alexey-milovidov
Copy link
Member Author

Yandex synchronization check (only for Yandex employees)

"Arcadia" build is using wrong build system, will fix.

@alexey-milovidov alexey-milovidov self-assigned this Jul 5, 2020
@alexey-milovidov alexey-milovidov merged commit ec563e5 into master Jul 5, 2020
@alexey-milovidov alexey-milovidov deleted the codeql branch July 5, 2020 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants