Fix overflow in basename(1)
This commit is contained in:
parent
c59894bd5c
commit
a7ad11ed5e
13
basename.c
13
basename.c
@ -17,8 +17,7 @@ usage(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *s;
|
char *s, *p;
|
||||||
size_t n;
|
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
default:
|
default:
|
||||||
@ -29,13 +28,11 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
s = basename(argv[0]);
|
s = basename(argv[0]);
|
||||||
if(argc == 2 && argv[1]) {
|
if(argc == 2) {
|
||||||
n = strlen(s) - strlen(argv[1]);
|
p = strstr(s, argv[1]);
|
||||||
if(!strcmp(&s[n], argv[1]))
|
if (p && p[strlen(p)] == '\0')
|
||||||
s[n] = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
puts(s);
|
puts(s);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user