venus: Make clang happy with strlcpy use
[openafs.git] / src / venus / afsio.c
index f8387c9..c19ca2e 100644 (file)
 #ifdef HAVE_DIRECT_H
 #include <direct.h>
 #endif
-#ifdef AFS_DARWIN_ENV
-#include <sys/malloc.h>
-#else
-#include <malloc.h>
-#endif
 #include <hcrypto/md5.h>
 #ifdef AFS_PTHREAD_ENV
 #include <assert.h>
@@ -85,7 +80,7 @@ static int CmdProlog(struct cmd_syndesc *, char **, char **,
 static int ScanFid(char *, struct AFSFid *);
 static afs_int32 GetVenusFidByFid(char *, char *, int, struct afscp_venusfid **);
 static afs_int32 GetVenusFidByPath(char *, char *, struct afscp_venusfid **);
-static int BreakUpPath(char *, char *, char *);
+static int BreakUpPath(char *, char *, char *, size_t);
 
 static char pnp[AFSPATHMAX];   /* filename of this program when called */
 static int verbose = 0;                /* Set if -verbose option given */
@@ -258,12 +253,11 @@ CmdProlog(struct cmd_syndesc *as, char **cellp, char **realmp,
 int
 main(int argc, char **argv)
 {
-    afs_int32 code = 0;
     struct cmd_syndesc *ts;
     char baseName[AFSNAMEMAX];
 
     /* try to get only the base name of this executable for use in logs */
-    if (BreakUpPath(argv[0], NULL, baseName) > 0)
+    if (BreakUpPath(argv[0], NULL, baseName, AFSNAMEMAX) > 0)
        strlcpy(pnp, baseName, AFSNAMEMAX);
     else
        strlcpy(pnp, argv[0], AFSPATHMAX);
@@ -375,7 +369,7 @@ main(int argc, char **argv)
     if (afscp_Init(NULL) != 0)
        exit(1);
 
-    code = cmd_Dispatch(argc, argv);
+    cmd_Dispatch(argc, argv);
 
     afscp_Finalize();
     exit(0);
@@ -520,7 +514,7 @@ GetVenusFidByFid(char *fidString, char *cellName, int onlyRW,
  *       2 if both dirName and baseName were filled in
  */
 static int
-BreakUpPath(char *fullPath, char *dirName, char *baseName)
+BreakUpPath(char *fullPath, char *dirName, char *baseName, size_t baseNameSize)
 {
     char *lastSlash;
     size_t dirNameLen = 0;
@@ -547,18 +541,18 @@ BreakUpPath(char *fullPath, char *dirName, char *baseName)
        /* then lastSlash points to the last path separator in fullPath */
        if (useDirName) {
            dirNameLen = strlen(fullPath) - strlen(lastSlash);
-           strlcpy(dirName, fullPath, dirNameLen + 1);
+           strlcpy(dirName, fullPath, min(dirNameLen + 1, baseNameSize));
            code++;
        }
        if (useBaseName) {
            lastSlash++;
-           strlcpy(baseName, lastSlash, strlen(lastSlash) + 1);
+           strlcpy(baseName, lastSlash, min(strlen(lastSlash) + 1, baseNameSize));
            code++;
        }
     } else {
        /* there are no path separators in fullPath -- it's just a baseName */
        if (useBaseName) {
-           strlcpy(baseName, fullPath, strlen(fullPath) + 1);
+           strlcpy(baseName, fullPath, min(strlen(fullPath) + 1, baseNameSize));
            code++;
        }
     }
@@ -878,7 +872,7 @@ writeFile(struct cmd_syndesc *as, void *unused)
            }
        }
        if (!append && !overWrite) { /* must create a new file in this case */
-           if ( BreakUpPath(fname, dirName, baseName) != 2 ) {
+           if ( BreakUpPath(fname, dirName, baseName, AFSNAMEMAX) != 2 ) {
                code = EINVAL;
                afs_com_err(pnp, code, "(must provide full AFS path)");
                afscp_FreeFid(newvfp);