[PATCH] ivi-controller: fixed string copy in controller_screen_screenshot

mateuszx.potrola at intel.com mateuszx.potrola at intel.com
Tue Mar 29 06:16:06 EDT 2016

From: Mateusz Polrola <mateuszx.potrola at intel.com>

With earlier implementation memory for NULL byte of l->filename string
was not being allocated by malloc (strlen is returning length of string
without NULL terminating byte) which may result in some random
characters appended in filename string.
Now strdup is begin used for string copy instead of malloc/strcpy.

Signed-off-by: Mateusz Polrola <mateuszx.potrola at intel.com>
 weston-ivi-shell/src/ivi-controller-impl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/weston-ivi-shell/src/ivi-controller-impl.c b/weston-ivi-shell/src/ivi-controller-impl.c
index 5fa78aa..15e677e 100644
--- a/weston-ivi-shell/src/ivi-controller-impl.c
+++ b/weston-ivi-shell/src/ivi-controller-impl.c
@@ -917,7 +917,7 @@ controller_screen_screenshot(struct wl_client *client,
-    l->filename = malloc(strlen(filename));
+    l->filename = strdup(filename);
     if(l->filename == NULL) {
         fprintf(stderr, "fails to allocate memory\n");
@@ -925,7 +925,6 @@ controller_screen_screenshot(struct wl_client *client,
     output = ivi_extension_screen_get_output(iviscrn->shell, iviscrn->layout_screen);
-    strcpy(l->filename, filename);
     l->listener.notify = controller_screenshot_notify;
     wl_signal_add(&output->frame_signal, &l->listener);

Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263

This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.

More information about the genivi-ivi-layer-management mailing list