From d81271640891fb8c364e8625e7a9f6ede21572f4 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 2 Mar 2013 11:44:02 +0000 Subject: [PATCH] readpwd: Make sure user supplies a passwdfile If the user supplies enough command line arguments, but doesn't provide a passwdfile, then we can end up trying to open whatever garbage is on the stack. Once we've finished parsing the command line arguments, make sure that a filename was supplied. Caught by coverity (#986009) Change-Id: Ice2fca16458a90d73ae6b5fadb0efa22ed0b185a Reviewed-on: http://gerrit.openafs.org/9441 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman --- src/ptserver/readpwd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ptserver/readpwd.c b/src/ptserver/readpwd.c index e0c5c28f9..8874fc5e9 100644 --- a/src/ptserver/readpwd.c +++ b/src/ptserver/readpwd.c @@ -55,6 +55,8 @@ main(afs_int32 argc, char **argv) afs_int32 verbose = 0; char *cellname = NULL; + buf[0] = '\0'; + if (argc < 2) { fprintf(stderr, "Usage: readpwd [-v] [-c cellname] passwdfile.\n"); exit(1); @@ -71,6 +73,12 @@ main(afs_int32 argc, char **argv) strncpy(buf, argv[i], 150); } } + + if (buf[0] == '\0') { + fprintf(stderr, "Usage: readpwd [-v] [-c cellname] passwdfile.\n"); + exit(1); + } + code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname); if (cellname) free(cellname); -- 2.39.5