From c358d7cbbdf24de7d62d9ae3f514201a31bed2f9 Mon Sep 17 00:00:00 2001 From: Ben Kaduk Date: Tue, 16 Jul 2013 20:39:56 -0400 Subject: [PATCH] Check for over/underflow while allocating PTS ids The behavior of signed integer over/underflow is implementation-defined, but even if the compiler is nice and just wraps around, we could get ourselves into trouble later on. Reviewed-on: http://gerrit.openafs.org/10091 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Reviewed-by: Mark Vitale Reviewed-by: Derrick Brashear (cherry picked from commit 6c7c185ba3ec6fbdda0651d18868e66edd655809) Change-Id: I1feb1879cce064760ae061538215b22b6fd55933 Reviewed-on: http://gerrit.openafs.org/10124 Tested-by: BuildBot Reviewed-by: Andrew Deason Reviewed-by: Stephan Wiesand --- src/ptserver/utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ptserver/utils.c b/src/ptserver/utils.c index 822df9948..18b0ccb59 100644 --- a/src/ptserver/utils.c +++ b/src/ptserver/utils.c @@ -349,7 +349,8 @@ AllocID(struct ubik_trans *at, afs_int32 flag, afs_int32 *aid) if (flag & PRGRP) { *aid = ntohl(cheader.maxGroup); - while (code && i < maxcount) { + /* Check for PRBADID to avoid wrap-around. */ + while (code && i < maxcount && *aid != PRBADID) { --(*aid); code = FindByID(at, *aid); i++; @@ -381,7 +382,7 @@ AllocID(struct ubik_trans *at, afs_int32 flag, afs_int32 *aid) return PRSUCCESS; } else { *aid = ntohl(cheader.maxID); - while (code && i < maxcount) { + while (code && i < maxcount && *aid != 0x7fffffff) { ++(*aid); code = FindByID(at, *aid); i++; -- 2.39.5