public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib/tst_uid_gid.c: fix checking return value errors about getpwuid_r/getgrgid_r
@ 2014-02-20  2:10 Zeng Linggang
  2014-02-20  7:53 ` Stanislav Kholmanskikh
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Zeng Linggang @ 2014-02-20  2:10 UTC (permalink / raw)
  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 <zenglg.jy@cn.fujitsu.com>
---
 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 <errno.h>
 #include <grp.h>
 #include <limits.h>
 #include <pwd.h>
@@ -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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-04-09 14:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-20  2:10 [LTP] [PATCH] lib/tst_uid_gid.c: fix checking return value errors about getpwuid_r/getgrgid_r Zeng Linggang
2014-02-20  7:53 ` Stanislav Kholmanskikh
2014-03-06 11:34   ` Zeng Linggang
2014-03-06 12:36     ` Stanislav Kholmanskikh
2014-03-10  8:13       ` Zeng Linggang
2014-03-13  8:33 ` Zeng Linggang
     [not found] ` <1396944482.2100.1.camel@G08JYZSD130126>
2014-04-08 11:19   ` chrubis
     [not found]     ` <5344069B.8010101@oracle.com>
2014-04-08 14:49       ` chrubis
2014-04-08 15:52         ` chrubis
     [not found]           ` <5344E5C8.3070306@oracle.com>
2014-04-09 13:08             ` chrubis
     [not found]               ` <53454939.2030704@oracle.com>
2014-04-09 13:23                 ` chrubis
2014-04-09 14:39                   ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox