From a900c5010a77c6f22991b1312be3daf41116a1a4 Mon Sep 17 00:00:00 2001 From: didg Date: Tue, 19 Sep 2006 00:08:00 +0000 Subject: [PATCH] in unicode function convert_charset needs trailing zero, spotted by HAT --- bin/megatron/nad.c | 6 +++--- bin/uniconv/uniconv.c | 6 +++--- etc/afpd/catsearch.c | 4 ++-- etc/afpd/desktop.c | 8 +++----- etc/afpd/mangle.c | 4 ++-- libatalk/unicode/charcnv.c | 18 ++++++++++++++---- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/bin/megatron/nad.c b/bin/megatron/nad.c index a679bd67..91e981d5 100644 --- a/bin/megatron/nad.c +++ b/bin/megatron/nad.c @@ -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( "." ); diff --git a/bin/uniconv/uniconv.c b/bin/uniconv/uniconv.c index 60b12e71..f62f33c0 100644 --- a/bin/uniconv/uniconv.c +++ b/bin/uniconv/uniconv.c @@ -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", diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index d425eed2..2c0a6a3d 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -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)) { diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index 7ef0af56..a0b0fda4 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -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 diff --git a/etc/afpd/mangle.c b/etc/afpd/mangle.c index 10314136..562a5976 100644 --- a/etc/afpd/mangle.c +++ b/etc/afpd/mangle.c @@ -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; diff --git a/libatalk/unicode/charcnv.c b/libatalk/unicode/charcnv.c index dc3d2c05..7619b721 100644 --- a/libatalk/unicode/charcnv.c +++ b/libatalk/unicode/charcnv.c @@ -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; } -- 2.39.2