From: Simon Wilkinson Date: Fri, 1 Mar 2013 11:09:04 +0000 (+0000) Subject: bucoord: Remove theoretical overflow of ubik array X-Git-Tag: upstream/1.6.10_pre1^2~157 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=2e644c3d860b5576be0cdf69b09b554fc4af1542;p=packages%2Fo%2Fopenafs.git bucoord: Remove theoretical overflow of ubik array The ubik connections array is NULL terminated, so we have to ensure that there is enough space for the trailing NULL. As the array is MAXSERVERS elements long, this means that we can only store MAXSERVERS-1 connections in it. This problem will never be encountered by the correct code, as the number of hosts returned from afsconf_Open is capped at MAXHOSTSPERCELL (currently 8). MAXSERVERS is currently 20. However, fix the bug in case we increase MAXHOSTSPERCELL at some point in the future. Caught by coverity (#985576) Reviewed-on: http://gerrit.openafs.org/9322 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Reviewed-by: Derrick Brashear (cherry picked from commit c0fba6eab519bd1bb6929b788361219f97da7212) Change-Id: I1e2556df6867ebb7b6b311e54a0271fb6fe631fd Reviewed-on: http://gerrit.openafs.org/11032 Tested-by: BuildBot Reviewed-by: Andrew Deason Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Stephan Wiesand --- diff --git a/src/bucoord/ubik_db_if.c b/src/bucoord/ubik_db_if.c index 92ac59ecc..e29e8f9ba 100644 --- a/src/bucoord/ubik_db_if.c +++ b/src/bucoord/ubik_db_if.c @@ -910,11 +910,15 @@ udbClientInit(int noAuthFlag, int localauth, char *cellName) if (&udbHandle.uh_scIndex == RX_SECIDX_NULL && !noAuthFlag) afs_com_err(whoami, 0, "Can't get tokens - running unauthenticated"); - if (info.numServers > MAXSERVERS) { + /* We have to have space for the trailing NULL that terminates the server + * conneciton array - so we can only store MAXSERVERS-1 real elements in + * that array. + */ + if (info.numServers >= MAXSERVERS) { afs_com_err(whoami, 0, "Warning: %d BDB servers exist for cell '%s', can only remember the first %d", - info.numServers, cellName, MAXSERVERS); - info.numServers = MAXSERVERS; + info.numServers, cellName, MAXSERVERS-1); + info.numServers = MAXSERVERS - 1; } /* establish connections to the servers. Check for failed connections? */