Skip to content

Commit

Permalink
fortify: Do not cast to "unsigned char"
Browse files Browse the repository at this point in the history
[ Upstream commit e9a40e1 ]

Do not cast to "unsigned char", as this needlessly creates type problems
when attempting builds without -Wno-pointer-sign[1]. The intent of the
cast is to drop possible "const" types.

[1] https://lore.kernel.org/lkml/CAHk-=wgz3Uba8w7kdXhsqR1qvfemYL+OFQdefJnkeqXG8qZ_pA@mail.gmail.com/

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Fixes: 3009f89 ("fortify: Allow strlen() and strnlen() to pass compile-time known lengths")
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
kees authored and gregkh committed Dec 31, 2022
1 parent 12695b4 commit ed88147
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/linux/fortify-string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void __write_overflow_field(size_t avail, size_t wanted) __compiletime_warning("

#define __compiletime_strlen(p) \
({ \
unsigned char *__p = (unsigned char *)(p); \
char *__p = (char *)(p); \
size_t __ret = SIZE_MAX; \
size_t __p_size = __member_size(p); \
if (__p_size != SIZE_MAX && \
Expand Down

0 comments on commit ed88147

Please sign in to comment.