5
orhun
5y

Anyone else suffering from CWE-126? (Buffer Over-read)
I'm struggling to find the right solution for fixing my issues with string operations.
Here's the Codacy report for those who want to see: https://app.codacy.com/manual/...
I'm creating more issues than fixing it. God damn it, C.

Comments
  • 6
    If I understand that correctly, you're relying on the input string being 0 terminated, and that falls flat if it isn't.

    An easy fix is to put in a "sentinel" 0 at the last allowed position of your input string buffer AFTER reading in the data to make sure you have 0 termination.
  • 3
    @Fast-Nop
    Thats also how scanf handles this particular problem.
  • 1
    Okay, I kind of solved the issues by avoiding to use strlen.
    ~ strnlen
Add Comment