From 815564d8f9c161183f092e40561cbb26f2024fc8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 5 Dec 2011 13:24:36 -0500 Subject: [PATCH] Fix ust app tracepoint list realloc - memcpy data _after_ reallocation (corruption fix), - fix off-by-one in size check (corruption fix), - multiply size by 2 each time size increase is needed (optimisation). Signed-off-by: Mathieu Desnoyers --- lttng-sessiond/ust-app.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lttng-sessiond/ust-app.c b/lttng-sessiond/ust-app.c index 69164126b..3847004d4 100644 --- a/lttng-sessiond/ust-app.c +++ b/lttng-sessiond/ust-app.c @@ -1383,12 +1383,11 @@ int ust_app_list_events(struct lttng_event **events) while ((ret = ustctl_tracepoint_list_get(app->key.sock, handle, &iter)) != -ENOENT) { - memcpy(tmp[count].name, iter.name, LTTNG_UST_SYM_NAME_LEN); /* TODO : get loglevel too */ - if (count > nbmem) { - DBG2("Reallocating event list from %zu to %zu bytes", nbmem, - nbmem + UST_APP_EVENT_LIST_SIZE); - nbmem += UST_APP_EVENT_LIST_SIZE; + if (count >= nbmem) { + DBG2("Reallocating event list from %zu to %zu entries", nbmem, + 2 * nbmem); + nbmem *= 2; tmp = realloc(tmp, nbmem * sizeof(struct lttng_event)); if (tmp == NULL) { PERROR("realloc ust app events"); @@ -1396,7 +1395,7 @@ int ust_app_list_events(struct lttng_event **events) goto rcu_error; } } - + memcpy(tmp[count].name, iter.name, LTTNG_UST_SYM_NAME_LEN); tmp[count].type = LTTNG_UST_TRACEPOINT; tmp[count].pid = app->key.pid; tmp[count].enabled = -1; -- 2.34.1