From 5b3c1042969daec38ccb260e61d665eda0c713ea 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". Change-Id: I0897b250fd885a1230d1622015eec9afe3450b46 Reviewed-on: http://gerrit.openafs.org/11745 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Benjamin Kaduk --- 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 a0197564a..8a4914dd2 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; } @@ -1141,7 +1143,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 5e5402cae..189e31360 100644 --- a/src/kauth/krb_udp.c +++ b/src/kauth/krb_udp.c @@ -294,7 +294,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 0a9d2e062..ed857f9ee 100644 --- a/src/vlserver/vldb_check.c +++ b/src/vlserver/vldb_check.c @@ -213,7 +213,7 @@ NameHash(char *volname) afs_int32 IdHash(afs_uint32 volid) { - return ((abs(volid)) % HASHSIZE); + return (volid % HASHSIZE); } #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" -- 2.39.5