From: Karol Lewandowski Date: Wed, 27 Apr 2016 14:03:03 +0000 (+0200) Subject: Janitorial: use snprintf() for string operations X-Git-Tag: accepted/tizen/common/20160428.144320^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F35%2F67635%2F2;p=platform%2Fcore%2Fsystem%2Flibdbuspolicy.git Janitorial: use snprintf() for string operations snprintf() guarantees terminating \0 byte for given size. Change-Id: I65cb90ea4466d0356cc02919d269da8843a7302f --- 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;