medium · M4 · MASVS-CODE-4 · PTKD-IOS-UNSAFE-C-STRING

    Unsafe C string function (buffer overflow risk)

    The binary imports an unbounded C string function (strcpy/strcat/sprintf/gets/stpcpy), which copies without a length check and is a classic stack/heap buffer overflow when the source is attacker-influenced.

    How it is exploited

    The binary imports an unbounded C string function (strcpy/strcat/sprintf/gets). When the source data is longer than the destination buffer, the copy overflows it. With attacker-controlled input this corrupts the stack or heap and, past the binary's mitigations, can lead to code execution.

    Why it matters

    Memory corruption and, in the worst case, remote or local code execution; at minimum a crash (denial of service).

    How to fix it

    1. Replace strcpy/strcat/sprintf with the bounded strlcpy/strlcat/snprintf and always pass the destination size.
    2. Never use gets; read with a bounded API.
    3. If the symbol came from a static dependency, update it; verify the finding against your own code first.

    Does your app have this?

    PTKD checks your build or your source project for PTKD-IOS-UNSAFE-C-STRING and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M4)