From 3bd4e8f797ce9834ff128468b777d870a9ee3dae Mon Sep 17 00:00:00 2001 From: Ben Kaduk Date: Fri, 13 Feb 2015 09:47:20 -0500 Subject: [PATCH] Fix incorrect uses of abs() abs(3) is a function of one variable of type int returning int. labs(3) is a function of one variable of type long returning long. labs(3) should be used when the input is of type long, as in kaprocs.c. Calling anything from the abs(3) family on a variable of unsigned type is a bogus type pun, and a logical operation which is a no-op. (Unsigned values are never negative and thus the absolute value function is the identity over the entire range of values representable in an unsigned type.) Just remove the use of abs() for unsigned values, as in kaprocs.c, krb_udp.c, and vldb_check.c While in kaprocs.c, wrap a long line that was touched for the conversion to labs(3), spell the argument to time(3) as NULL instead of 0, remove unneeded parentheses, and correct the spelling of "reserved". Reviewed-on: http://gerrit.openafs.org/11745 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Benjamin Kaduk (cherry picked from commit 5b3c1042969daec38ccb260e61d665eda0c713ea) Change-Id: I82038e41346479dad39466907b95f2d7540f6258 Reviewed-on: http://gerrit.openafs.org/11842 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk Reviewed-by: Stephan Wiesand --- src/kauth/kaprocs.c | 6 ++++-- src/kauth/krb_udp.c | 2 +- src/vlserver/vldb_check.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kauth/kaprocs.c b/src/kauth/kaprocs.c index 7298b862c..e055c71a2 100644 --- a/src/kauth/kaprocs.c +++ b/src/kauth/kaprocs.c @@ -711,7 +711,9 @@ ChangePassWord(struct rx_call *call, char *aname, char *ainstance, /* validate the request */ request_time = ntohl(request.time); /* reorder date */ kvno = ntohl(request.kvno); - if ((abs(request_time - time(0)) > KTC_TIME_UNCERTAINTY) || strncmp(request.label, KA_CPW_REQ_LABEL, sizeof(request.label)) || (request.spare) || (kvno > MAXKAKVNO)) { /* these are reseved */ + if (labs(request_time - time(NULL)) > KTC_TIME_UNCERTAINTY || + strncmp(request.label, KA_CPW_REQ_LABEL, sizeof(request.label)) || + request.spare || kvno > MAXKAKVNO) { /* these are reserved */ code = KABADREQUEST; goto abort; } @@ -1140,7 +1142,7 @@ Authenticate(int version, struct rx_call *call, char *aname, char *ainstance, } #endif /* EXPIREPW */ - if (abs(request.time - now) > KTC_TIME_UNCERTAINTY) { + if (request.time - now > KTC_TIME_UNCERTAINTY) { #if 0 if (oanswer->MaxSeqLen < sizeof(afs_int32)) code = KAANSWERTOOLONG; diff --git a/src/kauth/krb_udp.c b/src/kauth/krb_udp.c index b1f8ffad7..c98837050 100644 --- a/src/kauth/krb_udp.c +++ b/src/kauth/krb_udp.c @@ -297,7 +297,7 @@ UDP_Authenticate(int ksoc, struct sockaddr_in *client, char *name, code = KERB_ERR_NAME_EXP; /* XXX Could use another error code XXX */ goto abort; } - if (abs(startTime - now) > KTC_TIME_UNCERTAINTY) { + if (startTime - now > KTC_TIME_UNCERTAINTY) { code = KERB_ERR_SERVICE_EXP; /* was KABADREQUEST */ goto abort; } diff --git a/src/vlserver/vldb_check.c b/src/vlserver/vldb_check.c index 903b81b88..59f75d8ec 100644 --- a/src/vlserver/vldb_check.c +++ b/src/vlserver/vldb_check.c @@ -223,7 +223,7 @@ NameHash(char *volname) afs_int32 IdHash(afs_uint32 volid) { - return ((abs(volid)) % HASHSIZE); + return (volid % HASHSIZE); } #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" -- 2.39.5