From 2992e3d791e0e2bab05f9f827896a261e85128f4 Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Tue, 15 Mar 2016 16:35:59 +0900 Subject: [PATCH] Use thread-safe function Change-Id: I7e2c45a0aee9d0933b0997d5db850a1192d655c1 Signed-off-by: Myungki Lee --- src/isadmin.c | 9 +++++---- src/tzplatform_get.c | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/isadmin.c b/src/isadmin.c index 1d1d699..130f43e 100644 --- a/src/isadmin.c +++ b/src/isadmin.c @@ -42,9 +42,10 @@ int _has_system_group_static_(uid_t uid) { - struct passwd *userinfo = NULL; - struct group *systemgroupinfo = NULL; + struct passwd pwd, *userinfo = NULL; + struct group grp, *systemgroupinfo = NULL; const char *sysgrpname = NULL; + char buf[1024]; uid_t myuid = 0; gid_t system_gid = 0; gid_t *groups = NULL; @@ -63,7 +64,7 @@ int _has_system_group_static_(uid_t uid) { fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL"); return -1; } - systemgroupinfo = getgrnam(sysgrpname); + getgrnam_r(sysgrpname, &grp, buf, sizeof(buf), &systemgroupinfo); if(systemgroupinfo == NULL) { fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname); return -1; @@ -73,7 +74,7 @@ int _has_system_group_static_(uid_t uid) { /* Get all the gid of the given uid */ - userinfo = getpwuid(myuid); + getpwuid(myuid, &pwd, buf, sizeof(buf), &userinfo); /* Need to call this function now to get the number of group to make the malloc correctly sized */ diff --git a/src/tzplatform_get.c b/src/tzplatform_get.c index 4273460..b190c34 100644 --- a/src/tzplatform_get.c +++ b/src/tzplatform_get.c @@ -57,7 +57,8 @@ int main(int argc, char **argv) int all = 0, not = 0, query = 0, export = 0, space = 0, list = 0, cont = 0; int i, n, *sel, p; enum tzplatform_variable id; - struct passwd *spw; + struct passwd pwd, *spw; + char buf[1024]; /* parse args */ while(*argv && **argv=='-') { @@ -178,9 +179,9 @@ int main(int argc, char **argv) if (user) { for (i=0 ; '0' <= user[i] && user[i] <= '9' ; i++); if (user[i]) - spw = getpwnam(user); + getpwnam_r(user, &pwd, buf, sizeof(buf), &spw); else - spw = getpwuid((uid_t)atoi(user)); + getpwuid_r(user, &pwd, buf, sizeof(buf), &spw); if (!spw) { fprintf( stderr, "error! %s isn't standing for a valid user.\n", user); if (!cont) -- 2.7.4