
November 2, 1988. A Cornell grad student named Robert Morris releases a worm that spreads through, among other holes, the finger service, which read a network request into a fixed 512 byte buffer using gets, with no length check at all. Overrun the buffer and you owned the machine. The worm reinfected so hard it ground about ten percent of the internet to a halt overnight, and it led to the first felony conviction under the US computer fraud law. Copy into the buffer, but stop at its edge.
Repair this code
Repair the copy so it never writes past the buffer, truncating and null terminating within cap.
Steps
$ safe_copy(dst, 512, "hi")
2 (dst is "hi")
$ safe_copy(dst, 4, "hello")
3 (dst is "hel")
Expected files
Allowed functions
None. Write every helper yourself.
Loading solutions...