Tweaked the checking of the "limit" in safe_fname().
authorWayne Davison <wayned@samba.org>
Tue, 3 May 2005 16:44:47 +0000 (16:44 +0000)
committerWayne Davison <wayned@samba.org>
Tue, 3 May 2005 16:44:47 +0000 (16:44 +0000)
util.c

diff --git a/util.c b/util.c
index cde75717db5ced152f98526e7e4f40e73eb5dd16..6cbe7e1c7ecfaca928650345a273c5a37940e388 100644 (file)
--- a/util.c
+++ b/util.c
@@ -892,7 +892,7 @@ char *safe_fname(const char *fname)
        char *t;
 
        ndx = (ndx + 1) % MAX_SAFE_NAMES;
-       for (t = fbuf[ndx]; *fname && limit; fname++) {
+       for (t = fbuf[ndx]; *fname; fname++) {
                if (*fname == '\\') {
                        if ((limit -= 2) < 0)
                                break;
@@ -904,7 +904,8 @@ char *safe_fname(const char *fname)
                        sprintf(t, "\\%03o", *(uchar*)fname);
                        t += 4;
                } else {
-                       limit--;
+                       if (--limit < 0)
+                               break;
                        *t++ = *fname;
                }
        }