Return-Path: Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1WGJ6O-0006pn-Bo for ltp-list@lists.sourceforge.net; Thu, 20 Feb 2014 02:11:04 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1WGJ6K-0007qV-RQ for ltp-list@lists.sourceforge.net; Thu, 20 Feb 2014 02:11:04 +0000 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s1K2Aj7E009936 for ; Thu, 20 Feb 2014 10:10:51 +0800 Message-ID: <1392862246.1997.6.camel@G08JYZSD130126> From: Zeng Linggang Date: Thu, 20 Feb 2014 10:10:46 +0800 Mime-Version: 1.0 Subject: [LTP] [PATCH] lib/tst_uid_gid.c: fix checking return value errors about getpwuid_r/getgrgid_r List-Id: Linux Test Project General Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-list-bounces@lists.sourceforge.net To: ltp-list When we call getgrgid_r() to verify whether the corresponding gid is existent, if not, getgrgid_r() will return 0 or ENOENT or ESRCH or EBADF or EPERM... But tst_get_unused_gid() only check return value 0, this is not complete. For example, if the gid is not existent, getgrgid_r() in RHEL7 beta will return ENOENT, which will cause tst_get_unused_gid failed incorrectly. This is the same for getpwuid_r(). We should make tst_get_unused_uid/tst_get_unused_gid check all the possible return value. Signed-off-by: Zeng Linggang --- lib/tst_uid_gid.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/tst_uid_gid.c b/lib/tst_uid_gid.c index 3ba1ad6..a835c38 100644 --- a/lib/tst_uid_gid.c +++ b/lib/tst_uid_gid.c @@ -16,6 +16,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include @@ -44,10 +45,21 @@ uid_t tst_get_unused_uid(void) s = getpwuid_r(uid, &pwd, buf, bufsize, &result); if (result == NULL) { free(buf); - if (s == 0) + /* + * When the given name or gid was not found, getgrgid_r + * may return 0 or ENOENT or ESRCH or EBADF or EPERM + * or ... + */ + switch (s) { + case 0: + case ENOENT: + case ESRCH: + case EBADF: + case EPERM: return uid; - else + default: return -1; + } } } @@ -76,10 +88,21 @@ gid_t tst_get_unused_gid(void) s = getgrgid_r(gid, &grp, buf, bufsize, &result); if (result == NULL) { free(buf); - if (s == 0) + /* + * When the given name or gid was not found, getgrgid_r + * may return 0 or ENOENT or ESRCH or EBADF or EPERM + * or ... + */ + switch (s) { + case 0: + case ENOENT: + case ESRCH: + case EBADF: + case EPERM: return gid; - else + default: return -1; + } } } -- 1.8.4.2 ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list