PERFORCE change 31796 for review

Dag-Erling Smorgrav des at FreeBSD.org
Sat May 24 10:53:31 PDT 2003


http://perforce.freebsd.org/chv.cgi?CH=31796

Change 31796 by des at des.at.des.thinksec.com on 2003/05/24 10:52:28

	Return code paranoia: compare against 0 instead of -1.
	
	Suggested by:	Dmitry V. Levin <ldv at altlinux.org>

Affected files ...

.. //depot/projects/openpam/lib/openpam_borrow_cred.c#8 edit
.. //depot/projects/openpam/lib/openpam_dynamic.c#11 edit
.. //depot/projects/openpam/lib/openpam_restore_cred.c#7 edit
.. //depot/projects/openpam/lib/pam_getenv.c#15 edit
.. //depot/projects/openpam/lib/pam_putenv.c#11 edit
.. //depot/projects/openpam/lib/pam_setenv.c#11 edit

Differences ...

==== //depot/projects/openpam/lib/openpam_borrow_cred.c#8 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/openpam_borrow_cred.c#7 $
+ * $P4: //depot/projects/openpam/lib/openpam_borrow_cred.c#8 $
  */
 
 #include <sys/param.h>
@@ -76,7 +76,7 @@
 	scred->euid = geteuid();
 	scred->egid = getegid();
 	r = getgroups(NGROUPS_MAX, scred->groups);
-	if (r == -1) {
+	if (r < 0) {
 		FREE(scred);
 		RETURNC(PAM_SYSTEM_ERR);
 	}
@@ -88,8 +88,8 @@
 	}
 	if (geteuid() == pwd->pw_uid)
 		RETURNC(PAM_SUCCESS);
-	if (initgroups(pwd->pw_name, pwd->pw_gid) == -1 ||
-	      setegid(pwd->pw_gid) == -1 || seteuid(pwd->pw_uid) == -1) {
+	if (initgroups(pwd->pw_name, pwd->pw_gid) < 0 ||
+	      setegid(pwd->pw_gid) < 0 || seteuid(pwd->pw_uid) < 0) {
 		openpam_restore_cred(pamh);
 		RETURNC(PAM_SYSTEM_ERR);
 	}

==== //depot/projects/openpam/lib/openpam_dynamic.c#11 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/openpam_dynamic.c#10 $
+ * $P4: //depot/projects/openpam/lib/openpam_dynamic.c#11 $
  */
 
 #include <dlfcn.h>
@@ -62,7 +62,7 @@
 		goto buf_err;
 
 	/* try versioned module first, then unversioned module */
-	if (asprintf(&vpath, "%s.%d", path, LIB_MAJ) == -1)
+	if (asprintf(&vpath, "%s.%d", path, LIB_MAJ) < 0)
 		goto buf_err;
 	if ((dlh = dlopen(vpath, RTLD_LAZY)) == NULL) {
 		openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror());

==== //depot/projects/openpam/lib/openpam_restore_cred.c#7 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/openpam_restore_cred.c#6 $
+ * $P4: //depot/projects/openpam/lib/openpam_restore_cred.c#7 $
  */
 
 #include <sys/param.h>
@@ -64,9 +64,9 @@
 	if (scred == NULL)
 		RETURNC(PAM_SYSTEM_ERR);
 	if (scred->euid != geteuid()) {
-		if (seteuid(scred->euid) == -1 ||
-		    setgroups(scred->ngroups, scred->groups) == -1 ||
-		    setegid(scred->egid) == -1)
+		if (seteuid(scred->euid) < 0 ||
+		    setgroups(scred->ngroups, scred->groups) < 0 ||
+		    setegid(scred->egid) < 0)
 			RETURNC(PAM_SYSTEM_ERR);
 	}
 	pam_set_data(pamh, PAM_SAVED_CRED, NULL, NULL);

==== //depot/projects/openpam/lib/pam_getenv.c#15 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/pam_getenv.c#14 $
+ * $P4: //depot/projects/openpam/lib/pam_getenv.c#15 $
  */
 
 #include <stdlib.h>
@@ -60,7 +60,7 @@
 		RETURNS(NULL);
 	if (name == NULL || strchr(name, '=') != NULL)
 		RETURNS(NULL);
-	if ((i = openpam_findenv(pamh, name, strlen(name))) == -1)
+	if ((i = openpam_findenv(pamh, name, strlen(name))) < 0)
 		RETURNS(NULL);
 	for (str = pamh->env[i]; *str != '\0'; ++str) {
 		if (*str == '=') {

==== //depot/projects/openpam/lib/pam_putenv.c#11 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/pam_putenv.c#10 $
+ * $P4: //depot/projects/openpam/lib/pam_putenv.c#11 $
  */
 
 #include <stdlib.h>
@@ -64,7 +64,7 @@
 		RETURNC(PAM_SYSTEM_ERR);
 
 	/* see if the variable is already in the environment */
-	if ((i = openpam_findenv(pamh, namevalue, p - namevalue)) != -1) {
+	if ((i = openpam_findenv(pamh, namevalue, p - namevalue)) >= 0) {
 		if ((p = strdup(namevalue)) == NULL)
 			RETURNC(PAM_BUF_ERR);
 		FREE(pamh->env[i]);

==== //depot/projects/openpam/lib/pam_setenv.c#11 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/openpam/lib/pam_setenv.c#10 $
+ * $P4: //depot/projects/openpam/lib/pam_setenv.c#11 $
  */
 
 #include <stdlib.h>
@@ -67,7 +67,7 @@
 		RETURNC(PAM_SYSTEM_ERR);
 
 	/* is it already there? */
-	if (!overwrite && openpam_findenv(pamh, name, strlen(name)) != -1)
+	if (!overwrite && openpam_findenv(pamh, name, strlen(name)) >= 0)
 		RETURNC(PAM_SUCCESS);
 
 	/* set it... */


More information about the p4-projects mailing list