From cb9a942c00916543ebdd7e84e089483e6b9e0946 Mon Sep 17 00:00:00 2001 From: didg Date: Mon, 18 Sep 2006 00:23:58 +0000 Subject: [PATCH] in unicode function trailing zero needs to be wide, spotted by HAT --- bin/megatron/nad.c | 4 +--- bin/uniconv/uniconv.c | 3 +-- etc/afpd/catsearch.c | 8 +++----- etc/afpd/mangle.c | 4 ++-- etc/afpd/status.c | 4 ++-- libatalk/unicode/charcnv.c | 41 +++++++++++++++++++++++--------------- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/bin/megatron/nad.c b/bin/megatron/nad.c index be5561fb..a679bd67 100644 --- a/bin/megatron/nad.c +++ b/bin/megatron/nad.c @@ -1,5 +1,5 @@ /* - * $Id: nad.c,v 1.11.8.2.2.1 2005-02-10 01:23:08 didg Exp $ + * $Id: nad.c,v 1.11.8.2.2.2 2006-09-18 00:23:58 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 1f0a27b0..d425eed2 100644 --- a/etc/afpd/catsearch.c +++ b/etc/afpd/catsearch.c @@ -301,7 +301,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 ! */ @@ -861,7 +860,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 f8b4c854..10314136 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.4 2005-09-27 10:40:41 didg Exp $ + * $Id: mangle.c,v 1.16.2.1.2.12.2.5 2006-09-18 00:23:58 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 +1]; + static char buffer[MAXPATHLEN]; size_t len; size_t mfilenamelen; char *u; diff --git a/etc/afpd/status.c b/etc/afpd/status.c index 3aab5711..9247ef5b 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -1,5 +1,5 @@ /* - * $Id: status.c,v 1.13.6.11.2.2 2005-09-27 10:40:41 didg Exp $ + * $Id: status.c,v 1.13.6.11.2.3 2006-09-18 00:23:58 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 11b5e4db..dc3d2c05 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 * @@ -324,19 +346,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); } @@ -700,7 +712,6 @@ size_t charset_precompose ( charset_t ch, char * src, size_t inlen, char * dst, } free(buffer); - dst[len] = 0; return (len); } @@ -727,7 +738,6 @@ size_t charset_decompose ( charset_t ch, char * src, size_t inlen, char * dst, s } free(buffer); - dst[len] = 0; return (len); } @@ -783,7 +793,7 @@ static size_t pull_charset_flags (charset_t from_set, charset_t cap_charset, cha char* outbuf = (char*)dest; atalk_iconv_t descriptor; atalk_iconv_t descriptor_cap; - char *o_save, *s; + char *s; char h[MAXPATHLEN]; const char *h_buf; @@ -801,7 +811,6 @@ static size_t pull_charset_flags (charset_t from_set, charset_t cap_charset, cha i_len=srclen; o_len=destlen; - o_save=outbuf; conversion_loop: if ( flags && (*flags & CONV_UNESCAPEHEX)) { -- 2.39.2