Skip to content
Snippets Groups Projects
  • Kees Cook's avatar
    096a8aac
    clean up scary strncpy(dst, src, strlen(src)) uses · 096a8aac
    Kees Cook authored
    
    Fix various weird constructions of strncpy(dst, src, strlen(src)).
    
    Length limits should be about the space available in the destination,
    not repurposed as a method to either always include or always exclude a
    trailing NULL byte.  Either the NULL should always be copied (using
    strlcpy), or it should not be copied (using something like memcpy).
    Readable code should not depend on the weird behavior of strncpy when it
    hits the length limit.  Better to avoid the anti-pattern entirely.
    
    [akpm@linux-foundation.org: revert getdelays.c part due to missing bsd/string.h]
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>	[staging]
    Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>	[acpi]
    Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
    Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
    Cc: Ursula Braun <ursula.braun@de.ibm.com>
    Cc: Frank Blaschka <blaschka@linux.vnet.ibm.com>
    Cc: Richard Weinberger <richard@nod.at>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    096a8aac
    History
    clean up scary strncpy(dst, src, strlen(src)) uses
    Kees Cook authored
    
    Fix various weird constructions of strncpy(dst, src, strlen(src)).
    
    Length limits should be about the space available in the destination,
    not repurposed as a method to either always include or always exclude a
    trailing NULL byte.  Either the NULL should always be copied (using
    strlcpy), or it should not be copied (using something like memcpy).
    Readable code should not depend on the weird behavior of strncpy when it
    hits the length limit.  Better to avoid the anti-pattern entirely.
    
    [akpm@linux-foundation.org: revert getdelays.c part due to missing bsd/string.h]
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>	[staging]
    Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>	[acpi]
    Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
    Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
    Cc: Ursula Braun <ursula.braun@de.ibm.com>
    Cc: Frank Blaschka <blaschka@linux.vnet.ibm.com>
    Cc: Richard Weinberger <richard@nod.at>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.