From 4e46a80e1ebaa6daeb909e750314794828493c87 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 27 Apr 2016 16:03:03 +0200 Subject: [PATCH] Janitorial: use snprintf() for string operations snprintf() guarantees terminating \0 byte for given size. Change-Id: I65cb90ea4466d0356cc02919d269da8843a7302f --- src/libdbuspolicy1.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libdbuspolicy1.c b/src/libdbuspolicy1.c index 5178e88..e10d43b 100644 --- a/src/libdbuspolicy1.c +++ b/src/libdbuspolicy1.c @@ -228,7 +228,6 @@ static int dbuspolicy_init_udesc(struct kconn* kc, unsigned int bus_type, struct char buf[1024]; int attr_fd; int r; - int len; attr_fd = open("/proc/self/attr/current", O_RDONLY); if (attr_fd < 0) @@ -254,13 +253,8 @@ static int dbuspolicy_init_udesc(struct kconn* kc, unsigned int bus_type, struct if (!pwd || !gg) return -1; - len = sizeof(p_udesc->user) - 1; - strncpy(p_udesc->user, pwd->pw_name, len); - p_udesc->group[len] = 0; - - len = sizeof(p_udesc->group) - 1; - strncpy(p_udesc->group, gg->gr_name, len); - p_udesc->group[len] = 0; + snprintf(p_udesc->user, sizeof(p_udesc->user), "%s", pwd->pw_name); + snprintf(p_udesc->group, sizeof(p_udesc->group), "%s", gg->gr_name); p_udesc->bus_type = bus_type; p_udesc->conn = kc; -- 2.7.4