[hackers] [sbase] Fix overflow in basename(1) || sin

From: <git_AT_suckless.org>
Date: Thu, 13 Nov 2014 15:56:30 +0100

commit a7ad11ed5e3300c4d8eeab4d01a0a32eaf1f522d
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 13 14:24:26 2014 +0000

    Fix overflow in basename(1)

diff --git a/basename.c b/basename.c
index 5f6f0a3..cc35474 100644
--- a/basename.c
+++ b/basename.c
_AT_@ -17,8 +17,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- char *s;
- size_t n;
+ char *s, *p;
 
         ARGBEGIN {
         default:
_AT_@ -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;
 }
Received on Thu Nov 13 2014 - 15:56:30 CET

This archive was generated by hypermail 2.3.0 : Thu Nov 13 2014 - 16:00:17 CET