Alexandre Julliard : server: Store length of console title instead of null-terminating it.
Alexandre Julliard
julliard at winehq.org
Mon Mar 23 15:47:09 CDT 2020
Module: wine
Branch: master
Commit: 8d6d5a9bc6cb23290978066fe3ade991fe55d887
URL: https://source.winehq.org/git/wine.git/?a=commit;h=8d6d5a9bc6cb23290978066fe3ade991fe55d887
Author: Alexandre Julliard <julliard at winehq.org>
Date: Sat Mar 21 11:44:03 2020 +0100
server: Store length of console title instead of null-terminating it.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
server/console.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/server/console.c b/server/console.c
index c3b235d022..e05bc9668c 100644
--- a/server/console.c
+++ b/server/console.c
@@ -53,6 +53,7 @@ struct console_input
INPUT_RECORD *records; /* input records */
struct console_input_events *evt; /* synchronization event with renderer */
WCHAR *title; /* console title */
+ data_size_t title_len; /* length of console title */
WCHAR **history; /* lines history */
int history_size; /* number of entries in history array */
int history_index; /* number of used entries in history array */
@@ -339,6 +340,7 @@ static struct object *create_console_input( struct thread* renderer, int fd )
console_input->records = NULL;
console_input->evt = renderer ? create_console_input_events() : NULL;
console_input->title = NULL;
+ console_input->title_len = 0;
console_input->history_size = 50;
console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
console_input->history_index = 0;
@@ -779,16 +781,15 @@ static int set_console_input_info( const struct set_console_input_info_request *
}
if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
{
- WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
- if (new_title)
- {
- memcpy( new_title, title, len );
- new_title[len / sizeof(WCHAR)] = 0;
- free( console->title );
- console->title = new_title;
- evt.event = CONSOLE_RENDERER_TITLE_EVENT;
- console_input_events_append( console, &evt );
- }
+ WCHAR *new_title = NULL;
+
+ len = (len / sizeof(WCHAR)) * sizeof(WCHAR);
+ if (len && !(new_title = memdup( title, len ))) goto error;
+ free( console->title );
+ console->title = new_title;
+ console->title_len = len;
+ evt.event = CONSOLE_RENDERER_TITLE_EVENT;
+ console_input_events_append( console, &evt );
}
if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
{
@@ -1629,12 +1630,7 @@ DECL_HANDLER(get_console_input_info)
struct console_input *console;
if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
- if (console->title)
- {
- data_size_t len = strlenW( console->title ) * sizeof(WCHAR);
- if (len > get_reply_max_size()) len = get_reply_max_size();
- set_reply_data( console->title, len );
- }
+ if (console->title) set_reply_data( console->title, min( console->title_len, get_reply_max_size() ));
reply->history_mode = console->history_mode;
reply->history_size = console->history_size;
reply->history_index = console->history_index;
More information about the wine-cvs
mailing list