*/char *strnstr(const char *s1, const char *s2, size_t len){ size_t l2; l2 = strlen(s2); if (!l2) return (char *)s1; while (len >= l2) { len--; if (!memcmp(s1, s2, l2)) return (char *)s1; s1++; } return NULL;}EXPORT_SYMBOL(strnstr);#endif #ifndef __HAVE_ARCH_MEMCHR/** * memchr - Find a character in an area of memory. * @s: The memory area * @c: The byte to search for * @n: The size of the area. * * returns the address of the first occurrence of @c, or %NULL * if @c is not found */void *memchr(const void *s, int c, size_t n){ const unsigned char *p = s; while (n-- != 0) { if ((unsigned char)c == *p++) { return (void *)(p - 1); } } return NULL;}EXPORT_SYMBOL(memchr);#endif static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes){ while (bytes) { if (*start != value) return (void *)start; start++; bytes--; } return NULL;} /** * memchr_inv - Find an unmatching character in an area of memory. * @start: The memory area * @c: Find a character other than c * @bytes: The size of the area. * * returns the address of the first character other than @c, or %NULL * if the whole buffer contains just @c. */void *memchr_inv(const void *start, int c, size_t bytes){ u8 value = c; u64 value64; unsigned int words, prefix; if (bytes <= 16) return check_bytes8(start, value, bytes); value64 = value;#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101ULL;#elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) value64 *= 0x01010101; value64 |= value64 << 32;#else value64 |= value64 << 8; value64 |= value64 << 16; value64 |= value64 << 32;#endif prefix = (unsigned long)start % 8; if (prefix) { u8 *r; prefix = 8 - prefix; r = check_bytes8(start, value, prefix); if (r) return r; start += prefix; bytes -= prefix; } words = bytes / 8; while (words) { if (*(u64 *)start != value64) return check_bytes8(start, value, 8); start += 8; words--; } return check_bytes8(start, value, bytes % 8);}EXPORT_SYMBOL(memchr_inv); /** * strreplace - Replace all occurrences of character in string. * @s: The string to operate on. * @old: The character being replaced. * @new: The character @old is replaced with. * * Returns pointer to the nul byte at the end of @s. */char *strreplace(char *s, char old, char new){ for (; *s; ++s) if (*s == old) *s = new; return s;}EXPORT_SYMBOL(strreplace); void fortify_panic(const char *name){ pr_emerg("detected buffer overflow in %s\n", name); BUG();}EXPORT_SYMBOL(fortify_panic);Lines 1001–1131 of 1131. Previous lines
*/ char *strnstr(const char *s1, const char *s2, size_t len) { size_t l2; l2 = strlen(s2); if (!l2) return (char *)s1; while (len >= l2) { len--; if (!memcmp(s1, s2, l2)) return (char *)s1; s1++; } return NULL; } EXPORT_SYMBOL(strnstr); #endif #ifndef __HAVE_ARCH_MEMCHR /** * memchr - Find a character in an area of memory. * @s: The memory area * @c: The byte to search for * @n: The size of the area. * * returns the address of the first occurrence of @c, or %NULL * if @c is not found */ void *memchr(const void *s, int c, size_t n) { const unsigned char *p = s; while (n-- != 0) { if ((unsigned char)c == *p++) { return (void *)(p - 1); } } return NULL; } EXPORT_SYMBOL(memchr); #endif static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) { while (bytes) { if (*start != value) return (void *)start; start++; bytes--; } return NULL; } /** * memchr_inv - Find an unmatching character in an area of memory. * @start: The memory area * @c: Find a character other than c * @bytes: The size of the area. * * returns the address of the first character other than @c, or %NULL * if the whole buffer contains just @c. */ void *memchr_inv(const void *start, int c, size_t bytes) { u8 value = c; u64 value64; unsigned int words, prefix; if (bytes <= 16) return check_bytes8(start, value, bytes); value64 = value; #if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 value64 *= 0x0101010101010101ULL; #elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) value64 *= 0x01010101; value64 |= value64 << 32; #else value64 |= value64 << 8; value64 |= value64 << 16; value64 |= value64 << 32; #endif prefix = (unsigned long)start % 8; if (prefix) { u8 *r; prefix = 8 - prefix; r = check_bytes8(start, value, prefix); if (r) return r; start += prefix; bytes -= prefix; } words = bytes / 8; while (words) { if (*(u64 *)start != value64) return check_bytes8(start, value, 8); start += 8; words--; } return check_bytes8(start, value, bytes % 8); } EXPORT_SYMBOL(memchr_inv); /** * strreplace - Replace all occurrences of character in string. * @s: The string to operate on. * @old: The character being replaced. * @new: The character @old is replaced with. * * Returns pointer to the nul byte at the end of @s. */ char *strreplace(char *s, char old, char new) { for (; *s; ++s) if (*s == old) *s = new; return s; } EXPORT_SYMBOL(strreplace); void fortify_panic(const char *name) { pr_emerg("detected buffer overflow in %s\n", name); BUG(); } EXPORT_SYMBOL(fortify_panic);