From 5fe03442328eca8b70731da1a8d510aef74a3d1f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 27 Mar 2016 11:26:04 +0200 Subject: [PATCH] Fix invalid memory usage in event.c p_dup really only duplicates the given region of memory. It does not append a zero byte. Thus, the string we are using here was not zero-terminated. Fix this by just using lua_pushlstring() so that we do not have to worry about a null terminating the string at all. Signed-off-by: Uli Schlachter --- event.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/event.c b/event.c index 555978bf..b08ce2f8 100644 --- a/event.c +++ b/event.c @@ -793,7 +793,6 @@ event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev) if(ev->subCode == XCB_RANDR_NOTIFY_OUTPUT_CHANGE) { xcb_randr_output_t output = ev->u.oc.output; uint8_t connection = ev->u.oc.connection; - char *output_name = NULL; const char *connection_str = NULL; xcb_randr_get_output_info_reply_t *info = NULL; lua_State *L = globalconf_get_lua_State(); @@ -806,9 +805,6 @@ event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev) if(!info) return; - output_name = p_dup((char *)xcb_randr_get_output_info_name(info), - xcb_randr_get_output_info_name_length(info)); - switch(connection) { case XCB_RANDR_CONNECTION_CONNECTED: connection_str = "Connected"; @@ -821,11 +817,10 @@ event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev) break; } - lua_pushstring(L, output_name); + lua_pushlstring(L, (char *)xcb_randr_get_output_info_name(info), xcb_randr_get_output_info_name_length(info)); lua_pushstring(L, connection_str); signal_object_emit(L, &global_signals, "screen::change", 2); - p_delete(&output_name); p_delete(&info); /* The docs for RRSetOutputPrimary say we get this signal */