+ lib-string-allow-searching-for-nul-with-strnchr.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: lib/string.c: allow searching for NUL with strnchr
has been added to the -mm tree.  Its filename is
     lib-string-allow-searching-for-nul-with-strnchr.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/lib-string-allow-searching-for-nul-with-strnchr.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/lib-string-allow-searching-for-nul-with-strnchr.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Peter Rosin <peda@xxxxxxxxxx>
Subject: lib/string.c: allow searching for NUL with strnchr

Patch series "lib/string: search for NUL with strchr/strnchr".

I noticed an inconsistency where strchr and strnchr do not behave the same
with respect to the trailing NUL.  strchr is standardised and the kernel
function conforms, and the kernel relies on the behavior.  So, naturally
strchr stays as-is and strnchr is what I change.

While writing a few tests to verify that my new strnchr loop was sane, I
noticed that the tests for memset16/32/64 had a problem.  Since it's all
about the lib/string.c file I made a short series of it all...


This patch (of 3):

strchr considers the terminating NUL to be part of the string, and NUL can
thus be searched for with that function.  For consistency, do the same
with strnchr.

Link: http://lkml.kernel.org/r/20190506124634.6807-2-peda@xxxxxxxxxx
Signed-off-by: Peter Rosin <peda@xxxxxxxxxx>
Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 lib/string.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/lib/string.c~lib-string-allow-searching-for-nul-with-strnchr
+++ a/lib/string.c
@@ -400,6 +400,9 @@ EXPORT_SYMBOL(strncmp);
  * strchr - Find the first occurrence of a character in a string
  * @s: The string to be searched
  * @c: The character to search for
+ *
+ * Note that the %NUL-terminator is considered part of the string, and can
+ * be searched for.
  */
 char *strchr(const char *s, int c)
 {
@@ -453,12 +456,18 @@ EXPORT_SYMBOL(strrchr);
  * @s: The string to be searched
  * @count: The number of characters to be searched
  * @c: The character to search for
+ *
+ * Note that the %NUL-terminator is considered part of the string, and can
+ * be searched for.
  */
 char *strnchr(const char *s, size_t count, int c)
 {
-	for (; count-- && *s != '\0'; ++s)
+	while (count--) {
 		if (*s == (char)c)
 			return (char *)s;
+		if (*s++ == '\0')
+			break;
+	}
 	return NULL;
 }
 EXPORT_SYMBOL(strnchr);
_

Patches currently in -mm which might be from peda@xxxxxxxxxx are

lib-string-allow-searching-for-nul-with-strnchr.patch
lib-test_string-avoid-masking-memset16-32-64-failures.patch
lib-test_string-add-some-testcases-for-strchr-and-strnchr.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux