68cc101e8d65272ed56e0813bdca2672de3d4c3a angie Wed Jun 10 12:21:12 2015 -0700 Fix a memory-usage bug that was leading to weird symptoms such as random data stored in the cart and possibly also bad end cookie when freeing. lineFileNext can trash the string passed to lineFileOnString, so pass in a copy instead of the original string. refs #15506 diff --git src/hg/hgTables/userRegions.c src/hg/hgTables/userRegions.c index 739244c..40645c5 100644 --- src/hg/hgTables/userRegions.c +++ src/hg/hgTables/userRegions.c @@ -51,32 +51,35 @@ webIncludeHelpFile("hgTbUserRegionsHelp", FALSE); htmlClose(); } void doSetUserRegions(struct sqlConnection *conn) /* Respond to set regions button. */ { htmlOpen("Enter region definition\n"); doSetUserRegionsAfterOpen(conn); } static char *limitText(char *text) /* read text string and limit to maxRegions actual data lines */ { struct dyString *limitedText = dyStringNew(0); -/* yes, opening with FALSE so as not to destroy the original string */ -struct lineFile *lf = lineFileOnString("limitText", FALSE, text); +/* Even if using FALSE for zTerm, lineFile still does a memmove when it hits the end + * and thus clobbers the string, so call lineFileOnString on a copy: */ +char copy[strlen(text)+1]; +safecpy(copy, sizeof(copy), text); +struct lineFile *lf = lineFileOnString("limitText", FALSE, copy); char *lineStart = NULL; int lineLength = 0; int legitimateLineCount = 0; while (legitimateLineCount < maxRegions && lineFileNext(lf, &lineStart, &lineLength)) { char *s, c; s = skipLeadingSpaces(lineStart); c = s[0]; if (c != 0 && c != '#') ++legitimateLineCount; dyStringAppendN(limitedText, lineStart, lineLength); } if ((legitimateLineCount == maxRegions) && lineFileNext(lf, &lineStart, &lineLength)) warn("WARNING: defined regions limit of %d definitions reached at line %d<BR>\n", maxRegions, lf->lineIx-1); @@ -104,31 +107,30 @@ /* presence of fileName text overrides previously existing text area * contents */ if (userRegionFile != NULL && userRegionFile[0] != 0) { idText = cloneString(userRegionFile); cartRemove(cart, hgtaEnteredUserRegions); cartRemove(cart, hgtaUserRegionsFile); cartSetString(cart, hgtaEnteredUserRegions, idText); } char *lineLimitText = limitText(idText); if ( (strlen(lineLimitText) > 0) && (strlen(lineLimitText) != strlen(idText)) ) { - freeMem(idText); idText = lineLimitText; cartSetString(cart, hgtaEnteredUserRegions, lineLimitText); } else freeMem(lineLimitText); boolean success = TRUE; if (isNotEmpty(idText)) { int regionCount = 0; char *warnText = NULL; char *trashFileName = userRegionsParse(database, idText, maxRegions, maxErrors, ®ionCount, &warnText); if (isNotEmpty(warnText)) {