Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-27310 Fix Coverity scan issue in lnuid #18002

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion system/globalid/lnuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ namespace ln_uid {
fp = fopen("/dev/urandom", "r");
if (!fp || fread(&randomdata, 1, random_byte_count, fp) != random_byte_count)
{
// Should never happen, but if it does log it and ignore
// Should never happen, but if it does log it and fallback
OERRLOG("Could not read data from /dev/urandom");
auto randchar = []() -> char {
const char charset[] = "0123456789"
Copy link
Member

Choose a reason for hiding this comment

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

simpler is
return (char)rand() ;
there is no need for this to be human readable.

"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[static_cast<size_t>(rand()) % max_index];
};
std::generate_n(randomdata, random_byte_count, randchar);
}
if (fp)
fclose(fp);
Expand Down
Loading