You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "juniskane (via GitHub)" <gi...@apache.org> on 2024/03/11 11:06:30 UTC
[PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
juniskane opened a new pull request, #11889:
URL: https://github.com/apache/nuttx/pull/11889
## Summary
libs/libc/string: fix memmem() boundary case when needle is at end of haystack
This fixes calls like memmem("hello", 5, "lo", 2);
Also zero-length needle is deemed to exist at beginning of haystack. This behavior matches memmem() on Linux, FreeBSD, NetBSD and OpenBSD.
## Impact
Bug fix. Zero-length needle was incorrectly accessing bytes of needle.
## Testing
Passes there tests:
```
void test_memmem(void)
{
char *haystack = "hello";
char *s;
s = memmem(haystack, 5, "hel", 3);
assert(s == haystack);
s = memmem(haystack, 5, "lo", 2);
assert(s == haystack + 3);
s = memmem(haystack, 5, "hello", 5);
assert(s == haystack);
/* Compare '\0' bytes at string ends. */
s = memmem(haystack, 6, "o", 2);
assert(s == haystack + 4);
/* Must not find needle that is right after end of haystack. */
s = memmem("helloX", 5, "X", 1);
assert(s == NULL);
/* Too long needle should return NULL. */
s = memmem(haystack, 5, "hellohello", 10);
assert(s == NULL);
/* Zero length needle is deemed to reside at start of haystack. */
s = memmem(haystack, 5, "", 0);
assert(s == haystack);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1988639855
> @juniskane sounds like a good idea! @PetteriAimonen @xiaoxiang781216 What do you think?
>
> We could have a simple Pass/Fail suite with all tests. The ostest is more iterative testing tool to find issues.
it's better to integrate libc-test and add this test into it:
http://nsz.repo.hu/git/?p=libc-test;a=summary
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "juniskane (via GitHub)" <gi...@apache.org>.
juniskane commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1988524141
> @juniskane please include this test_memmem() to apps/testing/ostest
I view ostest as testing RTOS features like semaphores, scheduler, threads etc. Maybe we should have a separate libc testing suite? We already have this under testing/ directory related to libc features:
- arch_libc
- atomic
- fmemopen
- scanftest
- ostest/getopt.c
Maybe unify these under one test application? Just an idea, someone else has to do the work, not me :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "PetteriAimonen (via GitHub)" <gi...@apache.org>.
PetteriAimonen commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1989216435
I have run into some NuttX libc bugs before (which have since been fixed), so I think it would be a good idea to incorporate some established libc test suite.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1988584378
@juniskane sounds like a google idea! @PetteriAimonen @xiaoxiang781216 What do you think?
We could have a simple Pass/Fail suite with all tests. The ostest is more iterative testing tool to find issues.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "juniskane (via GitHub)" <gi...@apache.org>.
juniskane commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1988600012
I crafted a commit to add this testcase to ostest, so that it is stored at least somewhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #11889:
URL: https://github.com/apache/nuttx/pull/11889
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1988333599
@juniskane please include this test_memmem() to apps/testing/ostest
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1989150999
@xiaoxiang781216 but libc-test is focused on musl and probably only tested on NuttX and it is not integrated on NuttX. Also that project seems very inactive (one commit per year).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/string: fix memmem() boundary case when needle is at end of haystack [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #11889:
URL: https://github.com/apache/nuttx/pull/11889#issuecomment-1990037212
> @xiaoxiang781216 but libc-test is focused on musl and probably only tested on NuttX and it is not integrated on NuttX. Also that project seems very inactive (one commit per year).
It's always good to have more test to verify the implementation of NuttX's libc/posix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org