From eacd3140573d1122a3785823e4003bfc6352c431 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Sep 2007 22:08:59 +0000 Subject: r25138: More pstring elimination. Add a TALLOC_CTX parameter to unix_convert(). Jeremy. (This used to be commit 39c211a702e91c34c1a5a689e1b0c4530ea8a1ac) --- source3/lib/charcnv.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index c481c9a7e2..26581ba305 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -935,27 +935,40 @@ static size_t ucs2_align(const void *base_ptr, const void *p, int flags) * * * @param dest_len the maximum length in bytes allowed in the - * destination. If @p dest_len is -1 then no maximum is used. + * destination. **/ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); - pstring tmpbuf; + char *tmpbuf = NULL; + size_t ret; - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); + /* No longer allow a length of -1. */ + if (dest_len == (size_t)-1) { + smb_panic("push_ascii - dest_len == -1"); + return (size_t)0; + } if (flags & STR_UPPER) { - pstrcpy(tmpbuf, src); + tmpbuf = SMB_STRDUP(src); + if (!tmpbuf) { + smb_panic("malloc fail"); + return (size_t)0; + } strupper_m(tmpbuf); src = tmpbuf; } - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { src_len++; + } - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + ret = convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); + SAFE_FREE(tmpbuf); + if (ret == (size_t)-1) { + return 0; + } + return ret; } size_t push_ascii_fstring(void *dest, const char *src) @@ -1007,6 +1020,18 @@ size_t push_ascii_nstring(void *dest, const char *src) return dest_len; } +/******************************************************************** + Push and malloc an ascii string. src and dest null terminated. +********************************************************************/ + +size_t push_ascii_allocate(char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_allocate(NULL, CH_UNIX, CH_DOS, src, src_len, (void **)dest, True); +} + /** * Copy a string from a dos codepage source to a unix char* destination. * -- cgit