[hackers] [sbase] util/enmasse: fix double / || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Mon, 21 Jul 2014 17:43:47 +0200

commit ba8ca986a4c5c0e8ad419e7237da5b8dedd6002c
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu Jul 10 20:30:47 2014 +0000

    util/enmasse: fix double /
    
    Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>

diff --git a/util/enmasse.c b/util/enmasse.c
index f0e977b..a8ba4f7 100644
--- a/util/enmasse.c
+++ b/util/enmasse.c
_AT_@ -12,13 +12,13 @@ void
 enmasse(int argc, char *argv[], int (*fn)(const char *, const char *))
 {
         char *buf, *dir;
- int i;
+ int i, len;
         long size;
         struct stat st;
+ size_t dlen;
 
         if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
                 fnck(argv[0], argv[1], fn);
-
                 return;
         } else {
                 dir = (argc == 1) ? "." : argv[--argc];
_AT_@ -26,9 +26,14 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *))
 
         apathmax(&buf, &size);
         for(i = 0; i < argc; i++) {
- if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) >= size) {
+ dlen = strlen(dir);
+ if(dlen > 0 && dir[dlen - 1] == '/')
+ len = snprintf(buf, size, "%s%s", dir, basename(argv[i]));
+ else
+ len = snprintf(buf, size, "%s/%s", dir, basename(argv[i]));
+ if(len < 0 || len >= size) {
                         eprintf("%s/%s: filename too long
", dir,
- basename(argv[i]));
+ basename(argv[i]));
                 }
                 fnck(argv[i], buf, fn);
         }
Received on Mon Jul 21 2014 - 17:43:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 17:48:19 CEST