Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement internal strlcpy to replace the strncpy #620

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

arnopo
Copy link
Collaborator

@arnopo arnopo commented Sep 30, 2024

Compiler complain aboiut the use of strncpy that is not safe.

Already 3 PRs propose a fix of the issue:

As strlcpy seems to have been recently integrated into glibc, implement an internal copy for legacy support. This copy should replace the weak function implemented by the glibc.

@arnopo arnopo changed the title implementa intaerbnal strlcpy to replace the strncpy implement internal strlcpy to replace the strncpy Sep 30, 2024
@arnopo
Copy link
Collaborator Author

arnopo commented Sep 30, 2024

@wyr-7, @tomi-font,
Please, Could you check that this PR fits your needs and, if so, review the PR?

lib/utils/string.c Outdated Show resolved Hide resolved
tomi-font pushed a commit to tomi-font/zephyr-open-amp that referenced this pull request Sep 30, 2024
The strlcpy() function has only recently become available in glibc.
To ensure compatibility with legacy libc versions, this commit
implements an internal version of strlcpy().

The function has been adapted from the FreeBSD implementation to
fit our needs.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit c7c85bcfeb4f2c1be772efea8a889aa796d1a7c1)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
tomi-font pushed a commit to tomi-font/zephyr-open-amp that referenced this pull request Sep 30, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit e83acc98ad18f27bd1c12de808aaed84a0091791)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
tomi-font pushed a commit to tomi-font/zephyr-open-amp that referenced this pull request Sep 30, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit b1606070c9109ac581e1aa8dcff2871d0207e839)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
@@ -0,0 +1 @@
collect (PROJECT_LIB_SOURCES string.c)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many RTOS support strlcpy need some method to remove string.c or strlcpy from build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see a potential failure in not using this RTOS strlcpy implementation?

perhaps defining is a weak function would answer to your concern?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see a potential failure in not using this RTOS strlcpy implementation?

the link will report the multiple instance error if RTOS provide one implementation.

perhaps defining is a weak function would answer to your concern?

Yes, it's better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weak attribute added

tejlmand pushed a commit to tejlmand/open-amp that referenced this pull request Sep 30, 2024
The strlcpy() function has only recently become available in glibc.
To ensure compatibility with legacy libc versions, this commit
implements an internal version of strlcpy().

The function has been adapted from the FreeBSD implementation to
fit our needs.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit c7c85bcfeb4f2c1be772efea8a889aa796d1a7c1)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
tejlmand pushed a commit to tejlmand/open-amp that referenced this pull request Sep 30, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit e83acc98ad18f27bd1c12de808aaed84a0091791)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
tejlmand pushed a commit to tejlmand/open-amp that referenced this pull request Sep 30, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit b1606070c9109ac581e1aa8dcff2871d0207e839)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
The strlcpy() function has only recently become available in glibc.
To ensure compatibility with legacy libc versions, this commit
implements an internal version of strlcpy().

The function has been adapted from the FreeBSD implementation to
fit our needs.

Signed-off-by: Arnaud Pouliquen <[email protected]>
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
arnopo added a commit to zephyrproject-rtos/open-amp that referenced this pull request Oct 2, 2024
The strlcpy() function has only recently become available in glibc.
To ensure compatibility with legacy libc versions, this commit
implements an internal version of strlcpy().

The function has been adapted from the FreeBSD implementation to
fit our needs.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit c7c85bcfeb4f2c1be772efea8a889aa796d1a7c1)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
arnopo added a commit to zephyrproject-rtos/open-amp that referenced this pull request Oct 2, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit e83acc98ad18f27bd1c12de808aaed84a0091791)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
arnopo added a commit to zephyrproject-rtos/open-amp that referenced this pull request Oct 2, 2024
The strncpy function does not ensure that the destination string is
null-terminated. To address this issue, replace strncpy with the
internal strlcpy function, which guarantees null-termination of the
destination string.

Note: (void)strlcpy(...) indicates that the return value is intentionally
ignored.

Signed-off-by: Arnaud Pouliquen <[email protected]>
(cherry picked from commit b1606070c9109ac581e1aa8dcff2871d0207e839)

Upstream PR: OpenAMP/open-amp#620

Signed-off-by: Tomi Fontanilles <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
tomi-font pushed a commit to tomi-font/zephyr-open-amp that referenced this pull request Oct 3, 2024
Origin:
	OpenAMP/open-amp#620

Commits:
	e233473d14654f08468595ad0dbe8f7e58acf267
	8591566382d055acd33f9d23e6826a8a4b0a1881
	1aecdc737d463b4ff1ece36847f4f2e68d4ffe4a

Status:
	Cherry pick PR that fixes the `stringop-truncation`
	compilation errors due to former usage of `strncpy()`.

Signed-off-by: Tomi Fontanilles <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants