Skip to content

generateRandomBytes is faulty#325

Merged
vincent-richard merged 2 commits intokisli:masterfrom
jengelh:rand
Jul 21, 2025
Merged

generateRandomBytes is faulty#325
vincent-richard merged 2 commits intokisli:masterfrom
jengelh:rand

Conversation

@jengelh
Copy link
Contributor

@jengelh jengelh commented Jul 8, 2025

  • not checking read() result leads to undefined bytes in the output; fill them up with the fallback loop
  • fallback loop erroneously uses %255; this produces a non-uniform distribution of the result

jengelh added 2 commits July 8, 2025 10:34
posixHandler.cpp: In member function 'virtual void
vmime::platforms::posix::posixHandler::generateRandomBytes(unsigned
char*, unsigned int)': posixHandler.cpp:281:21: warning: ignoring
return value of 'ssize_t read(int, void*, size_t)' declared with
attribute 'warn_unused_result' [-Wunused-result]
  281 |                 read(fd, buffer, count);
x % 255 produces values in the range [0..254], which is wrong.
@vincent-richard vincent-richard merged commit 5bbb3a1 into kisli:master Jul 21, 2025
1 check passed
@jengelh jengelh deleted the rand branch July 21, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants