]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/mangle.c
more strncpy --> strlcpy fixes
[netatalk.git] / etc / afpd / mangle.c
index 7b669f7b5e0aabef9c2bfe41a5cb0a463dddad73..4a6d9eb9bc5dd33a6dd6d04d4e4d8b4e07e60f67 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: mangle.c,v 1.16.2.1.2.5 2003-10-14 00:28:26 bfernhomberg Exp $ 
+ * $Id: mangle.c,v 1.16.2.1.2.8 2004-02-14 15:47:20 didg Exp $ 
  *
  * Copyright (c) 2002. Joe Marcus Clarke (marcus@marcuscom.com)
  * All Rights Reserved.  See COPYRIGHT.
 #include <ctype.h>
 #include "mangle.h"
 #include "desktop.h"
+#include <atalk/util.h>  
 
 #define hextoint( c )   ( isdigit( c ) ? c - '0' : c + 10 - 'A' )
 #define isuxdigit(x)    (isdigit(x) || (isupper(x) && isxdigit(x)))
 
-
-
 static char *demangle_checks ( const struct vol *vol, char* uname, char * mfilename, size_t prefix, char * ext)
 {
     u_int16_t flags;
@@ -112,12 +111,14 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx
 {
     char *t;
     char *u_name;
-    u_int32_t id = 0;
+    u_int32_t id, file_id;
     static char buffer[12 + MAXPATHLEN + 1];
     int len = 12 + MAXPATHLEN + 1;
     struct dir *dir;
     size_t prefix;
 
+    id = file_id = 0;
+
     t = strchr(mfilename, MANGLE_CHAR);
     if (t == NULL) {
         return mfilename;
@@ -139,7 +140,7 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx
         return mfilename;
     }
 
-    id = htonl(id);
+    file_id = id = htonl(id);
     if (osx) {
         *osx = id;
     }
@@ -168,7 +169,7 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx
         }
         if (!osx) {
             /* convert back to mac name and check it's the same */
-            t = utompath(vol, u_name, id, utf8_encoding());
+            t = utompath(vol, u_name, file_id, utf8_encoding());
             if (!strcmp(t, mfilename)) {
                 return u_name;
             }
@@ -227,15 +228,16 @@ mangle(const struct vol *vol, char *filename, char *uname, cnid_t id, int flags)
        }
     }
     m = mfilename;
-    memset(m, 0, MAX_LENGTH + 1);
     k = sprintf(mangle_suffix, "%c%X", MANGLE_CHAR, ntohl(id));
 
-    strncpy(m, filename, MAX_LENGTH - k - ext_len);
+    strlcpy(m, filename, MAX_LENGTH - k - ext_len +1);
     if (*m == 0) {
         strcat(m, "???");
     }
     strcat(m, mangle_suffix);
-    strncat(m, ext, ext_len);
+    if (ext) {
+       strncat(m, ext, ext_len);
+    }
 
     return m;
 }