]> arthur.barton.de Git - netatalk.git/commitdiff
in unicode function convert_charset needs trailing zero, spotted by HAT
authordidg <didg>
Tue, 19 Sep 2006 00:08:00 +0000 (00:08 +0000)
committerdidg <didg>
Tue, 19 Sep 2006 00:08:00 +0000 (00:08 +0000)
bin/megatron/nad.c
bin/uniconv/uniconv.c
etc/afpd/catsearch.c
etc/afpd/desktop.c
etc/afpd/mangle.c
libatalk/unicode/charcnv.c

index a679bd67e15dae58a4a402614164c0444004e8f1..91e981d52203fa7f206fda9f8fb9aa7f6667a725 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: nad.c,v 1.11.8.2.2.2 2006-09-18 00:23:58 didg Exp $
+ * $Id: nad.c,v 1.11.8.2.2.3 2006-09-19 00:08:00 didg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -317,7 +317,7 @@ static char *utompathiconv(char *upath)
     char        *m, *u;
     u_int16_t    flags = CONV_IGNORE | CONV_UNESCAPEHEX;
     size_t       outlen;
-    static char         mpath[MAXPATHLEN];
+    static char         mpath[MAXPATHLEN +2]; /* for convert_charset dest_len parameter +2 */
 
     m = mpath;
     outlen = strlen(upath);
@@ -352,7 +352,7 @@ char *mtoupathiconv(char *mpath)
     size_t       inplen;
     size_t       outlen;
     u_int16_t    flags = 0;
-    static char         upath[MAXPATHLEN];
+    static char         upath[MAXPATHLEN +2]; /* for convert_charset dest_len parameter +2 */
 
     if ( *mpath == '\0' ) {
         return( "." );
index 60b12e7182133674646b4e794d7bf9fff76f5ac7..f62f33c0920258b54d5b35234d5833cb1718bb17 100644 (file)
@@ -142,7 +142,7 @@ static int do_rename( char* src, char *dst, struct stat *st)
 
 static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
 {
-       static char   buffer[MAXPATHLEN];
+       static char   buffer[MAXPATHLEN +2];  /* for convert_charset dest_len parameter +2 */
        size_t outlen = 0;
        unsigned char *p,*q;
        int require_conversion = 0;
@@ -171,14 +171,14 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
        q=buffer;
        p=name;
 
-       outlen = convert_charset(ch_from, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer), &flags);
+       outlen = convert_charset(ch_from, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer) -2, &flags);
        if ((size_t)-1 == outlen) {
           if ( ch_to == CH_UTF8) {
                /* maybe name is already in UTF8? */
                flags = conv_flags;
                q = (char*) buffer;
                p = name;
-               outlen = convert_charset(ch_to, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer), &flags);
+               outlen = convert_charset(ch_to, ch_to, ch_mac, p, strlen(p), q, sizeof(buffer) -2, &flags);
                if ((size_t)-1 == outlen) {
                        /* it's not UTF8... */
                        fprintf(stderr, "ERROR: conversion from '%s' to '%s' for '%s' in DID %u failed!!!\n", 
index d425eed23a6f60bfb27bcca19e7d92a3d32d9701..2c0a6a3d810141071adde345088995718e68e354 100644 (file)
@@ -97,7 +97,7 @@ struct scrit {
     u_int16_t offcnt;           /* Offspring count */
        struct finderinfo finfo;    /* Finder info */
        char lname[64];             /* Long name */ 
-       char utf8name[512];         /* UTF8 name */
+       char utf8name[514];         /* UTF8 or UCS2 name */ /* for convert_charset dest_len parameter +2 */
 };
 
 /*
@@ -258,7 +258,7 @@ static int crit_check(struct vol *vol, struct path *path) {
        struct adouble *adp = NULL;
        time_t c_date, b_date;
        u_int32_t ac_date, ab_date;
-       static char convbuf[512];
+       static char convbuf[514]; /* for convert_charset dest_len parameter +2 */
        size_t len;
 
        if (S_ISDIR(path->st.st_mode)) {
index 7ef0af569a197b87531a14c95b4017b05924daef..a0b0fda488cdf122f51e6695a4a8b51df96dc0d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: desktop.c,v 1.26.2.4.2.18.2.6 2006-09-18 09:16:07 didg Exp $
+ * $Id: desktop.c,v 1.26.2.4.2.18.2.7 2006-09-19 00:08:00 didg Exp $
  *
  * See COPYRIGHT.
  *
@@ -618,8 +618,8 @@ char *dtfile(const struct vol *vol, u_char creator[], char *ext )
  * mpath is only a filename 
  * did filename parent directory ID.
 */
-static char  upath[ MAXPATHLEN + 1];
-static char  mpath[ MAXPATHLEN + 1];
+static char  upath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
+static char  mpath[ MAXPATHLEN + 2];/* for convert_charset dest_len parameter +2 */
 
 char *mtoupath(const struct vol *vol, char *mpath, cnid_t did, int utf8)
 {
@@ -658,7 +658,6 @@ char *mtoupath(const struct vol *vol, char *mpath, cnid_t did, int utf8)
         LOG(log_error, logtype_afpd, "conversion from %s to %s for %s failed.", (utf8)?"UTF8-MAC":vol->v_maccodepage, vol->v_volcodepage, mpath);
            return NULL;
     }
-    upath[outlen] = 0;
 
 #ifdef DEBUG
     LOG(log_debug, logtype_afpd, "mtoupath: '%s':'%s'", mpath, upath);
@@ -691,7 +690,6 @@ char *utompath(const struct vol *vol, char *upath, cnid_t id, int utf8)
        goto utompath_error;
     }
 
-    mpath[outlen] = 0; 
     if (!(flags & CONV_REQMANGLE)) 
         flags = 0;
     else
index 10314136e363d7b26e4b0dfdbc7cb237a0960066..562a59767386da0f8947c56d4e9577bdde0f83b5 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: mangle.c,v 1.16.2.1.2.12.2.5 2006-09-18 00:23:58 didg Exp $ 
+ * $Id: mangle.c,v 1.16.2.1.2.12.2.6 2006-09-19 00:08:01 didg Exp $ 
  *
  * Copyright (c) 2002. Joe Marcus Clarke (marcus@marcuscom.com)
  * All Rights Reserved.  See COPYRIGHT.
@@ -25,7 +25,7 @@
 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];
+    static char buffer[MAXPATHLEN +2];  /* for convert_charset dest_len parameter +2 */
     size_t len;
     size_t mfilenamelen;
     char *u;
index dc3d2c056a806667248ca92bd2e72f866376c9d9..7619b721b26357dd2c4b1811623b40a6ab6d8246 100644 (file)
@@ -1008,19 +1008,23 @@ escape_slash:
     return destlen -o_len;
 }
 
+/*
+ * FIXME the size is a mess we really need a malloc/free logic
+ *`dest size must be dest_len +2
+*/
 size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, char* src, size_t src_len, char* dest, size_t dest_len, u_int16_t *flags)
 {
        size_t i_len, o_len;
        ucs2_t *u;
-       ucs2_t buffer[MAXPATHLEN];
-       ucs2_t buffer2[MAXPATHLEN];
+       ucs2_t buffer[MAXPATHLEN +2];
+       ucs2_t buffer2[MAXPATHLEN +2];
        int composition = 0;
        
        lazy_initialize_conv();
 
        /* convert from_set to UCS2 */
        if ((size_t)(-1) == ( o_len = pull_charset_flags( from_set, cap_charset, src, src_len, 
-                                                          (char *) buffer, sizeof(buffer), flags)) ) {
+                                                          (char *) buffer, sizeof(buffer) -2, flags)) ) {
                LOG(log_error, logtype_default, "Conversion failed ( %s to CH_UCS2 )", charset_name(from_set));
                return (size_t) -1;
        }
@@ -1036,7 +1040,7 @@ size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_cha
        if (CHECK_FLAGS(flags, CONV_DECOMPOSE) || (charsets[to_set] && charsets[to_set]->flags & CHARSET_DECOMPOSED) )
            composition = 2;
  
-       i_len = sizeof(buffer2);
+       i_len = sizeof(buffer2) -2;
        u = buffer2;
 
        switch (composition) {
@@ -1053,6 +1057,9 @@ size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_cha
                return (size_t)(-1);
            break;
        }
+       /* null terminate */
+       u[i_len] = 0;
+       u[i_len +1] = 0;
                
        /* Do case conversions */       
        if (CHECK_FLAGS(flags, CONV_TOUPPER)) {
@@ -1068,6 +1075,9 @@ size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_cha
                       "Conversion failed (CH_UCS2 to %s):%s", charset_name(to_set), strerror(errno));
                return (size_t) -1;
        }
+       /* null terminate */
+       dest[o_len] = 0;
+       dest[o_len +1] = 0;
 
        return o_len;
 }