]> arthur.barton.de Git - netatalk.git/commitdiff
in unicode function trailing zero needs to be wide, spotted by HAT
authordidg <didg>
Mon, 18 Sep 2006 01:06:44 +0000 (01:06 +0000)
committerdidg <didg>
Mon, 18 Sep 2006 01:06:44 +0000 (01:06 +0000)
bin/megatron/nad.c
bin/uniconv/uniconv.c
etc/afpd/catsearch.c
etc/afpd/mangle.c
etc/afpd/status.c
libatalk/unicode/charcnv.c

index dac81a0982ea090d8f3e406cc8de984bffef21e0..8f4fbf9fe562eb23392447bb5712323e7fb79721 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nad.c,v 1.12 2005-04-28 20:49:20 bfernhomberg Exp $
+ * $Id: nad.c,v 1.13 2006-09-18 01:06:44 didg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -337,7 +337,6 @@ static char *utompathiconv(char *upath)
         goto utompath_error;
     }
 
-    mpath[outlen] = 0;
     if (flags & CONV_REQMANGLE) 
        goto utompath_error;
 
@@ -382,7 +381,6 @@ char *mtoupathiconv(char *mpath)
         fprintf (stderr, "conversion from %s to %s for %s failed.", vol.v_maccodepage, vol.v_volcodepage, mpath);
         return(mtoupathcap( upath ));
     }
-    upath[outlen] = 0;
 
     return( upath );
 }
index 9955c2dca904d57cbd8c87a111f32fdba00f057f..60b12e7182133674646b4e794d7bf9fff76f5ac7 100644 (file)
@@ -185,7 +185,6 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
                                from_charset, to_charset, name, ntohl(cur_did));
                        return name;
                }
-               buffer[outlen] = 0;
 
                if (!strcmp(buffer, name)) {
                        return name;
@@ -195,7 +194,7 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
                        from_charset, to_charset, name, ntohl(cur_did));
           return name;
        }
-       buffer[outlen] = 0;
+
        if (strcmp (name, buffer)) {
            if (dry_run) {
                fprintf(stdout, "dry_run: would rename %s to %s.\n", name, buffer);
index d927ad4b36dce74a1d08a1a47ad79d0245f34d6b..82576652f01c2df3c04775138c16f757fa7bf737 100644 (file)
@@ -303,7 +303,7 @@ static int crit_check(struct vol *vol, struct path *path) {
        if ((c1.rbitmap & (1<<DIRPBIT_LNAME))) { 
                if ( (size_t)(-1) == (len = convert_string(vol->v_maccharset, CH_UCS2, path->m_name, strlen(path->m_name), convbuf, 512)) )
                        goto crit_check_ret;
-               convbuf[len] = 0; 
+
                if ((c1.rbitmap & (1<<CATPBIT_PARTIAL))) {
                        if (strcasestr_w( (ucs2_t*) convbuf, (ucs2_t*) c1.lname) == NULL)
                                goto crit_check_ret;
@@ -316,7 +316,7 @@ static int crit_check(struct vol *vol, struct path *path) {
                if ( (size_t)(-1) == (len = convert_charset( CH_UTF8_MAC, CH_UCS2, CH_UTF8, path->m_name, strlen(path->m_name), convbuf, 512, &flags))) {
                        goto crit_check_ret;
                }
-               convbuf[len] = 0; 
+
                if (c1.rbitmap & (1<<CATPBIT_PARTIAL)) {
                        if (strcasestr_w((ucs2_t *) convbuf, (ucs2_t*)c1.utf8name) == NULL)
                                goto crit_check_ret;
@@ -829,10 +829,9 @@ int catsearch_afp(AFPObj *obj _U_, char *ibuf, int ibuflen,
         /* Get the long filename */    
                memcpy(tmppath, bspec1 + spec1[1] + 1, (bspec1 + spec1[1])[0]);
                tmppath[(bspec1 + spec1[1])[0]]= 0;
-               len = convert_string ( vol->v_maccharset, CH_UCS2, tmppath, strlen(tmppath), c1.lname, 64);
+               len = convert_string ( vol->v_maccharset, CH_UCS2, tmppath, strlen(tmppath), c1.lname, sizeof(c1.lname));
         if (len == (size_t)(-1))
             return AFPERR_PARAM;
-               c1.lname[len] = 0;
 
 #if 0  
                /* FIXME: do we need it ? It's always null ! */
@@ -863,7 +862,6 @@ int catsearch_afp(AFPObj *obj _U_, char *ibuf, int ibuflen,
                len = convert_charset(CH_UTF8_MAC, CH_UCS2, CH_UTF8, c1.utf8name, namelen, c1.utf8name, 512, &flags);
         if (len == (size_t)(-1))
             return AFPERR_PARAM;
-               c1.utf8name[len]=0;
     }
     
     /* Call search */
index eb1f39eff254279c1388d18b84f1616eb143d691..6c124b912cb3f8590377246aacc251d52f3e1485 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: mangle.c,v 1.17 2005-04-28 20:49:44 bfernhomberg Exp $ 
+ * $Id: mangle.c,v 1.18 2006-09-18 01:06:44 didg Exp $ 
  *
  * Copyright (c) 2002. Joe Marcus Clarke (marcus@marcuscom.com)
  * All Rights Reserved.  See COPYRIGHT.
@@ -41,7 +41,7 @@ static size_t mangle_extension(const struct vol *vol, const char* uname,
 static char *demangle_checks ( const struct vol *vol, char* uname, char * mfilename, size_t prefix, char * ext)
 {
     u_int16_t flags;
-    static char buffer[MAXPATHLEN +1];
+    static char buffer[MAXPATHLEN];
     size_t len;
     size_t mfilenamelen;
 
index 92642c8ba74897e2e8f992988b625c4722110767..f92c14d1fb08e3a9db2374874ba97df859000a90 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: status.c,v 1.17 2005-05-03 14:55:10 didg Exp $
+ * $Id: status.c,v 1.18 2006-09-18 01:06:44 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -85,7 +85,7 @@ static int status_server(char *data, const char *server, const struct afp_option
     nbp_name(server, &Obj, &Type, &Zone);
     if ((size_t)-1 == (len = convert_string( 
                        options->unixcharset, options->maccharset, 
-                       Obj, strlen(Obj), buf, 31)) ) {
+                       Obj, strlen(Obj), buf, sizeof(buf))) ) {
        len = MIN(strlen(Obj), 31);
        *data++ = len;
        memcpy( data, Obj, len );
index b79d776ac1afa4ca4ad0197f2863e2d86ce6a345..67ca07a83e779d9dee95ed2750d9c80182be38fa 100644 (file)
@@ -274,6 +274,28 @@ void init_iconv(void)
        }
 }
 
+/**
+ *
+ **/
+static size_t add_null(charset_t to, char *buf, size_t bytesleft, size_t len)
+{
+       /* Terminate the string */
+       if (to == CH_UCS2 && bytesleft >= 2) {
+               buf[len]   = 0;
+               buf[len+1] = 0;
+
+       }
+       else if ( to != CH_UCS2 && bytesleft > 0 )
+               buf[len]   = 0;
+       else {
+               errno = E2BIG;
+               return (size_t)(-1);
+       }
+
+       return len;
+}
+
 /**
  * Convert string from one encoding to another, making error checking etc
  *
@@ -331,19 +353,9 @@ static size_t convert_string_internal(charset_t from, charset_t to,
                LOG(log_debug, logtype_default,"Conversion error: %s",reason);
                return (size_t)-1;
        }
-
+       
        /* Terminate the string */
-       if (to == CH_UCS2 && destlen-o_len >= 2) {
-               o_save[destlen-o_len]   = 0;
-               o_save[destlen-o_len+1] = 0;
-       }
-       else if ( to != CH_UCS2 && destlen-o_len > 0 )
-               o_save[destlen-o_len] = 0;
-       else {
-               /* FIXME: what should we do here, string *might* be unterminated. E2BIG? */
-       }
-
-       return destlen-o_len;
+       return add_null( to, o_save, o_len, destlen -o_len);
 }
 
 
@@ -707,7 +719,6 @@ size_t charset_precompose ( charset_t ch, char * src, size_t inlen, char * dst,
        }
        
        free(buffer);
-       dst[len] = 0;
        return (len);
 }
 
@@ -734,7 +745,6 @@ size_t charset_decompose ( charset_t ch, char * src, size_t inlen, char * dst, s
        }
 
        free(buffer);
-       dst[len] = 0;
        return (len);
 }