From 7597fdda3ff949077829727c26f4bd289c4ae285 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) Reviewed-on: http://gerrit.openafs.org/9546 Reviewed-by: Jeffrey Altman Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit d672d5ee78d7673f3c42a7a343989b2bd4dca02b) Change-Id: Id86f5488bfb3bbf5794af43e9f8fe84a2fe796c3 Reviewed-on: http://gerrit.openafs.org/11064 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Andrew Deason Reviewed-by: Stephan Wiesand --- 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 2e35d3b495..9eae4d0372 100644 --- a/src/update/client.c +++ b/src/update/client.c @@ -193,10 +193,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); }