From fed5dac9f25f7fbd74b6834ce6f087eaf31be2f2 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 2 Mar 2013 09:59:20 +0000 Subject: [PATCH] auth: Don't overflow hostName array afsconf_cell's hostName structure is a fixed length. Don't overflow it by writing whatever comes back from gethostbyaddr into it. Use strlcpy to catch an overflow, and if one occurs, just use "UNKNOWNHOST", rather than a truncated host name. Caught by coverity (#985906) Change-Id: Iaa927f3e4860d99166789e8dc4950a03ea2237e4 Reviewed-on: http://gerrit.openafs.org/9354 Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- src/auth/writeconfig.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/auth/writeconfig.c b/src/auth/writeconfig.c index 9d8d479ca..ad7c0b9fd 100644 --- a/src/auth/writeconfig.c +++ b/src/auth/writeconfig.c @@ -54,7 +54,12 @@ VerifyEntries(struct afsconf_cell *aci) if (!th) { strcpy(aci->hostName[i], "UNKNOWNHOST"); } else { - strcpy(aci->hostName[i], th->h_name); + if (strlcpy(aci->hostName[i], + th->h_name, + sizeof(aci->hostName[i])) + >= sizeof(aci->hostName[i])) { + strcpy(aci->hostName[i], "UNKNOWNHOST"); + } } } } -- 2.39.5