From d672d5ee78d7673f3c42a7a343989b2bd4dca02b Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 4 Mar 2013 16:22:08 +0000 Subject: [PATCH] upserver: Don't overflow file and hostname buffers If the user specifies a ridiculously long command line, don't overflow the filename or hostname buffers with what they supply. Caught by coverity (#985911) Change-Id: Ia73f9fb94491f5691358eec1d13dbdd2651a604c Reviewed-on: http://gerrit.openafs.org/9546 Reviewed-by: Jeffrey Altman Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/update/client.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/update/client.c b/src/update/client.c index bdcfd521fd..c822d3d233 100644 --- a/src/update/client.c +++ b/src/update/client.c @@ -177,10 +177,18 @@ main(int argc, char **argv) ("Usage: upclient [-crypt] [-clear] [-t ] [-verbose]* + [-help]\n"); exit(1); } - } else if (strlen(hostname) == 0) - strcpy(hostname, argv[a]); - else { - strcpy(filename, argv[a]); + } else if (strlen(hostname) == 0) { + if (strlcpy(hostname, argv[a], sizeof(hostname)) + >= sizeof(hostname)) { + fprintf(stderr, "Supplied hostname is too long\n"); + exit(1); + } + } else { + if (strlcpy(filename, argv[a], sizeof(filename)) + >= sizeof(filename)) { + fprintf(stderr, "Supplied filename is too long\n"); + exit(1); + } FilepathNormalize(filename); AddToList(&dirname, filename); }