s3/winbindd: use == -1 instead of < 0 for error checking uid_t
authorAurelien Aptel <aaptel@suse.com>
Wed, 9 Mar 2016 12:43:09 +0000 (13:43 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 1 Jul 2016 03:22:36 +0000 (05:22 +0200)
The sign of the uid_t type is left unspecified by POSIX. It's defined as
an unsigned 32b int on Linux, therefore the < 0 check is always
false.

For unsigned version of uid_t, "uid == -1" will implicitely cast -1 to
unsigned making it a valid test for both signed and unsigned version of
uid_t.

This commit makes the cast to (uid_t) explicit anyway.

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Fri Jul  1 05:22:36 CEST 2016 on sn-devel-144

source3/winbindd/winbindd_cred_cache.c
source3/winbindd/winbindd_pam.c

index e113f998a3b4230ffa996400fced668798eb379b..20b4d55fb80f7a9aab26a05d2b66861bb156d7ac 100644 (file)
@@ -503,7 +503,7 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
        NTSTATUS ntret;
 
        if ((username == NULL && princ_name == NULL) ||
-           ccname == NULL || uid < 0) {
+           ccname == NULL || uid == (uid_t)-1) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
index 2cfd88ae6db6f06d08aa73847b9213e7c7268fcb..8ec4fe4a6a155e66c7b876a95eeb45c30400457e 100644 (file)
@@ -555,7 +555,7 @@ uid_t get_uid_from_request(struct winbindd_request *request)
 
        uid = request->data.auth.uid;
 
-       if (uid < 0) {
+       if (uid == (uid_t)-1) {
                DEBUG(1,("invalid uid: '%u'\n", (unsigned int)uid));
                return -1;
        }
@@ -2311,7 +2311,7 @@ enum winbindd_result winbindd_dual_pam_logoff(struct winbindd_domain *domain,
 
 #ifdef HAVE_KRB5
 
-       if (state->request->data.logoff.uid < 0) {
+       if (state->request->data.logoff.uid == (uid_t)-1) {
                DEBUG(0,("winbindd_pam_logoff: invalid uid\n"));
                goto process_result;
        }