7a48ee92468a7bb4f778372c37ee2d43186681ff
chmalee
  Wed Mar 12 15:24:09 2025 -0700
Changes from code review, refs #35318

diff --git src/hg/hgHubConnect/hooks/hooklib.c src/hg/hgHubConnect/hooks/hooklib.c
index d88fe7f2ef4..c008cda925c 100644
--- src/hg/hgHubConnect/hooks/hooklib.c
+++ src/hg/hgHubConnect/hooks/hooklib.c
@@ -19,32 +19,33 @@
 
 char *prettyFileSize(long size)
 /* Return a string representing the size of a file */
 {
 char buf[32];
 sprintWithGreekByte(buf, sizeof(buf), size);
 return cloneString(buf);
 }
 
 char *encodePath(char *path)
 /* Return a string where each individual component of a '/' separated
  * string has been cgiEncoded, but not the '/' chars themselves */
 {
 int maxSeps = 256;
 char *pathArr[maxSeps]; // errAbort if more than maxSeps subdirs
-int numChops = chopString(path, "/", pathArr, maxSeps);
-if (numChops > maxSeps)
+char *copy = cloneString(path);
+int numChops = chopString(copy, "/", pathArr, maxSeps);
+if (numChops >= maxSeps)
     errAbort("Too many subdirectories. Fix filesystem layout of upload and try again");
 struct dyString *ret = dyStringNew(0);
 int i = 0;
 for (; i < numChops; i++)
     {
     // we can ignore .. and . in paths, it is an error if hubtools is creating these names
     // don't errAbort right now because hubtools does send things like 'hubName/.'
     // as a parentDir, but that should be fixed soon
     if (sameString(pathArr[i], ".") || sameString(pathArr[i], ".."))
         {
         continue;
         }
     dyStringPrintf(ret, "%s/", cgiEncodeFull(pathArr[i]));
     }
 return dyStringCannibalize(&ret);