Skip to content

TF-A implementation of memcpy_s() does not comply with C11 standard. #3

@sandrine-bailleux-arm

Description

@sandrine-bailleux-arm

memcpy_s() function got introduced in the C11 standard. TF-A libc provides an implementation of it in file lib/libc/memcpy_s.c.

This implementation does not fully comply with the C11 standard for the following reasons:

  1. (dsize > ssize) is allowed by the standard and thus should not be treated as an error. In this case, memcpy_s() should just copy ssize bytes.
    Note that (ssize > dsize), on the other hand, is a genuine error case and TF-A code is correct for this one. It matches the following sentence from the C11 standard:

n shall not be greater than s1max

  1. The following behaviour from the C11 standard is not implemented:

If there is a runtime-constraint violation, the memcpy_s function stores zeros in the first s1max characters of the object pointed to by s1 if s1 is not a null pointer and s1max is not greater than RSIZE_MAX.

  1. I don't see anything in the C11 standard that forbids ssize to be zero. It just would not copy any byte at all but it should not be treated as an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions