Fix null dereference in basename

On older kernels (<=linux-5.17), argv[0] can be null. Basename would
call strrchr with null if argc==0. Fixes issue #680
This commit is contained in:
skyler-ferrante 2023-03-22 12:46:56 -04:00 committed by Serge Hallyn
parent 300d6ef45c
commit c089196e15

View File

@ -21,6 +21,10 @@
#include "prototypes.h" #include "prototypes.h"
/*@observer@*/const char *Basename (const char *str) /*@observer@*/const char *Basename (const char *str)
{ {
if (str == NULL) {
abort ();
}
char *cp = strrchr (str, '/'); char *cp = strrchr (str, '/');
return (NULL != cp) ? cp + 1 : str; return (NULL != cp) ? cp + 1 : str;