Janitorial: use snprintf() for string operations 35/67635/2 accepted/tizen/common/20160428.144320 accepted/tizen/ivi/20160428.003159 accepted/tizen/mobile/20160428.005122 accepted/tizen/tv/20160428.003007 accepted/tizen/wearable/20160428.003329 submit/submit.001/20160427.185628 submit/tizen/20160427.185759
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 27 Apr 2016 14:03:03 +0000 (16:03 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 27 Apr 2016 14:30:27 +0000 (07:30 -0700)
snprintf() guarantees terminating \0 byte for given
size.

Change-Id: I65cb90ea4466d0356cc02919d269da8843a7302f

src/libdbuspolicy1.c

index 5178e88..e10d43b 100644 (file)
@@ -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;