From: Mathieu Desnoyers Date: Mon, 8 May 2017 12:15:20 +0000 (-0400) Subject: Cleanup: initialize data to 0 X-Git-Tag: v2.11.0-rc1~596 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8446e5ebcadad1fbd043e37ed4f2862b5e628022;p=lttng-tools.git Cleanup: initialize data to 0 Valgrind catches read of uninitialized data caused by the on-stack "data" argument which ends up not being fully initialized (it contains a union). Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/runas.c b/src/common/runas.c index 081a3d28e..946ea3101 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -466,6 +466,7 @@ int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid) { struct run_as_data data; + memset(&data, 0, sizeof(data)); DBG3("mkdir() recursive %s with mode %d for uid %d and gid %d", path, (int) mode, (int) uid, (int) gid); strncpy(data.u.mkdir.path, path, PATH_MAX - 1); @@ -479,6 +480,7 @@ int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { struct run_as_data data; + memset(&data, 0, sizeof(data)); DBG3("mkdir() %s with mode %d for uid %d and gid %d", path, (int) mode, (int) uid, (int) gid); strncpy(data.u.mkdir.path, path, PATH_MAX - 1); @@ -492,6 +494,7 @@ int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) { struct run_as_data data; + memset(&data, 0, sizeof(data)); DBG3("open() %s with flags %X mode %d for uid %d and gid %d", path, flags, (int) mode, (int) uid, (int) gid); strncpy(data.u.open.path, path, PATH_MAX - 1); @@ -506,6 +509,7 @@ int run_as_unlink(const char *path, uid_t uid, gid_t gid) { struct run_as_data data; + memset(&data, 0, sizeof(data)); DBG3("unlink() %s with for uid %d and gid %d", path, (int) uid, (int) gid); strncpy(data.u.unlink.path, path, PATH_MAX - 1);