Fix overflow in basename(1)

This commit is contained in:
sin 2014-11-13 14:24:26 +00:00
parent c59894bd5c
commit a7ad11ed5e

View File

@ -17,8 +17,7 @@ usage(void)
int
main(int argc, char *argv[])
{
char *s;
size_t n;
char *s, *p;
ARGBEGIN {
default:
@ -29,13 +28,11 @@ main(int argc, char *argv[])
usage();
s = basename(argv[0]);
if(argc == 2 && argv[1]) {
n = strlen(s) - strlen(argv[1]);
if(!strcmp(&s[n], argv[1]))
s[n] = '\0';
if(argc == 2) {
p = strstr(s, argv[1]);
if (p && p[strlen(p)] == '\0')
*p = '\0';
}
puts(s);
return 0;
}