]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Fix null dereference in basename
authorskyler-ferrante <sjf5462@rit.edu>
Wed, 22 Mar 2023 16:46:56 +0000 (12:46 -0400)
committerSerge Hallyn <serge@hallyn.com>
Mon, 27 Mar 2023 15:10:37 +0000 (10:10 -0500)
On older kernels (<=linux-5.17), argv[0] can be null. Basename would
call strrchr with null if argc==0. Fixes issue #680

libmisc/basename.c

index fe916532240d85c55be278909ec79e5d71e64298..95a2f85dd6ce5d30361f86b435770b65e8c43ebf 100644 (file)
 #include "prototypes.h"
 /*@observer@*/const char *Basename (const char *str)
 {
+       if (str == NULL) {
+               abort ();
+       }
+
        char *cp = strrchr (str, '/');
 
        return (NULL != cp) ? cp + 1 : str;