From: didg Date: Mon, 18 Sep 2006 01:06:44 +0000 (+0000) Subject: in unicode function trailing zero needs to be wide, spotted by HAT X-Git-Tag: before_sfm~3 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=6590d40ae8032ad963288710c826a068039525c3 in unicode function trailing zero needs to be wide, spotted by HAT --- diff --git a/bin/megatron/nad.c b/bin/megatron/nad.c index dac81a09..8f4fbf9f 100644 --- a/bin/megatron/nad.c +++ b/bin/megatron/nad.c @@ -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 ); } diff --git a/bin/uniconv/uniconv.c b/bin/uniconv/uniconv.c index 9955c2dc..60b12e71 100644 --- a/bin/uniconv/uniconv.c +++ b/bin/uniconv/uniconv.c @@ -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); diff --git a/etc/afpd/catsearch.c b/etc/afpd/catsearch.c index d927ad4b..82576652 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -303,7 +303,7 @@ static int crit_check(struct vol *vol, struct path *path) { if ((c1.rbitmap & (1<v_maccharset, CH_UCS2, path->m_name, strlen(path->m_name), convbuf, 512)) ) goto crit_check_ret; - convbuf[len] = 0; + if ((c1.rbitmap & (1<m_name, strlen(path->m_name), convbuf, 512, &flags))) { goto crit_check_ret; } - convbuf[len] = 0; + if (c1.rbitmap & (1<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 */ diff --git a/etc/afpd/mangle.c b/etc/afpd/mangle.c index eb1f39ef..6c124b91 100644 --- a/etc/afpd/mangle.c +++ b/etc/afpd/mangle.c @@ -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; diff --git a/etc/afpd/status.c b/etc/afpd/status.c index 92642c8b..f92c14d1 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -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 ); diff --git a/libatalk/unicode/charcnv.c b/libatalk/unicode/charcnv.c index b79d776a..67ca07a8 100644 --- a/libatalk/unicode/charcnv.c +++ b/libatalk/unicode/charcnv.c @@ -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); }