Password generator in C: the fix that is not one
Three hunks, not one, and running each three times is what exposes them. Version A prints the same password on every launch, because unseeded rand() starts from the same state every time. Version B seeds it and does vary, so the visible bug is genuinely fixed. It is still not secure: the seed is the clock, so anyone who knows roughly when it ran has only a handful of seeds to try. The runs below are a second apart for that reason, on both sides: a second is long enough for the clock seed to move, so Version A repeating itself cannot be put down to the runs being too close together.
VERSION A — INSECURE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ cc --version
Apple clang version 17.0.0 (clang-1700.6.4.2)
Target: arm64-apple-darwin25.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin$ sleep 1; ./password-rand
FZXC0wg0LvaJ6atJ$ sleep 1; ./password-rand
FZXC0wg0LvaJ6atJ$ sleep 1; ./password-rand
FZXC0wg0LvaJ6atJVERSION B — STILL INSECURE
Three hunks separate the two files; they are identical everywhere the diff does not mark. Their documentation blocks differ as well, compared above.
Documentation block: 10 lines removed, 14 added
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Difference: 1 line removed, 4 lines added.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 unchanged lines |
$ cc --version
Apple clang version 17.0.0 (clang-1700.6.4.2)
Target: arm64-apple-darwin25.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin$ sleep 1; ./password-srand
7RlqzsGfaeE7gNYc$ sleep 1; ./password-srand
Cq7spdmVlOeFbnHk$ sleep 1; ./password-srand
HFTtePIKv83OWD0tNEXT
This file accompanies LLMs Can Write Code, but Cannot Read Your Mind, which is where the claim it checks is made.
ALL SOURCE EXHIBITS →