widl: Don't use fixed size buffer in ctl2_encode_string.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-11-08 20:01:31 +01:00 committed by Alexandre Julliard
parent 908c2bec28
commit d5c745e467
1 changed files with 8 additions and 4 deletions

View File

@ -342,11 +342,14 @@ static int ctl2_encode_string(
const char *string, /* [I] The string to encode. */ const char *string, /* [I] The string to encode. */
char **result) /* [O] A pointer to a pointer to receive the encoded string. */ char **result) /* [O] A pointer to a pointer to receive the encoded string. */
{ {
int length; char *converted_string;
static char converted_string[0x104]; size_t length, size;
int offset; int offset;
length = strlen(string); length = strlen(string);
size = (length + 5) & ~3;
if (length < 3) size += 4;
converted_string = xmalloc(size);
memcpy(converted_string + 2, string, length); memcpy(converted_string + 2, string, length);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
@ -365,8 +368,7 @@ static int ctl2_encode_string(
for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57; for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
*result = converted_string; *result = converted_string;
return size;
return (length + 5) & ~3;
} }
/**************************************************************************** /****************************************************************************
@ -604,6 +606,7 @@ static int ctl2_alloc_string(
string_space = typelib->typelib_segment_data[MSFT_SEG_STRING] + offset; string_space = typelib->typelib_segment_data[MSFT_SEG_STRING] + offset;
memcpy(string_space, encoded_string, length); memcpy(string_space, encoded_string, length);
free(encoded_string);
return offset; return offset;
} }
@ -684,6 +687,7 @@ static int alloc_importfile(
importfile->lcid = typelib->typelib_header.lcid2; importfile->lcid = typelib->typelib_header.lcid2;
importfile->version = major_version | (minor_version << 16); importfile->version = major_version | (minor_version << 16);
memcpy(&importfile->filename, encoded_string, length); memcpy(&importfile->filename, encoded_string, length);
free(encoded_string);
return offset; return offset;
} }