44ccfacbe3a3d4b300f80d48651c77837a4b571e
galt
  Tue Apr 26 11:12:02 2022 -0700
SQL INJECTION Prevention Version 2 - this improves our methods by making subclauses of SQL that get passed around be both easy and correct to use. The way that was achieved was by getting rid of the obscure and not well used functions sqlSafefFrag and sqlDyStringPrintfFrag and replacing them with the plain versions of those functions, since these are not needed anymore. The new version checks for NOSQLINJ in unquoted %-s which is used to include SQL clauses, and will give an error the NOSQLINJ clause is not present, and this will automatically require the correct behavior by developers. sqlDyStringPrint is a very useful function, however because it was not enforced, users could use various other dyString functions and they operated without any awareness or checking for SQL correct use. Now those dyString functions are prohibited and it will produce an error if you try to use a dyString function on a SQL string, which is simply detected by the presence of the NOSQLINJ prefix.

diff --git src/hg/altSplice/affySplice/altProbes.c src/hg/altSplice/affySplice/altProbes.c
index a29928f..ab6bb27 100644
--- src/hg/altSplice/affySplice/altProbes.c
+++ src/hg/altSplice/affySplice/altProbes.c
@@ -2351,31 +2351,31 @@
 	}
     if(sortScoreHash != NULL)
 	score = sortScoreForSplice(nameForSplice(event->splice, namePath));
     bed = pathToBed(altPath->path, event->splice, -1, -1, FALSE);
     chrom = cloneString(bed->chrom);
     chromStart = bed->chromStart;
     chromEnd = bed->chromEnd;
     strand = bed->strand[0];
 
     if(newDb != NULL)
 	{
 	if(liftOverCoords(&chrom, &chromStart, &chromEnd, &strand))
 	    useDb = newDb;
 	}
 /* overlapPercent = percentIntronBasesOverlappingCons(chrom, chromStart,chromEnd); */
-    buff = newDyString(256);
+    buff = dyStringNew(256);
 
 /*     if(brainSpPSetOut != NULL)  */
 /*      { */
 /*      skipPath = namePath; */
 /*      skipPSet = skipPath->beds[0]->name; */
 /*      if(onlyTwoPaths(event)) */
 /*          incPath = event->altPathList->next; */
 /*      else */
 /*          incPath = NULL; */
 /*      fprintf(brainSpPSetOut, "%s\t", refSeqForPSet(skipPSet)); */
 /*      fprintf(brainSpPSetOut, "%s\t", skipPSet); */
 /*      if(incPath != NULL) */
 /*          { */
 /*          fprintf(brainSpPSetOut, "%d\t", incPath->probeCount); */
 /*          for(i = 0; i < incPath->probeCount; i++)  */
@@ -2942,31 +2942,31 @@
 	    cassetteExonSkipCount++;
 	}
     brainSpecificPathCount++;
     brainSpecificEvent = TRUE;
     fillInSequences(event, slLastEl(event->splice->paths),
 		    &upSeq, &downSeq, &exonSeq, &upSeqBed, &downSeqBed);
 
 
     /* Write out the data. */
     if (event->flipScore >= optionFloat("minFlip", -200000) 
     &&  event->flipScore <= optionFloat("maxFlip", 200000) 
     &&  event->percentUltra >= optionFloat("minIntCons", 0.0))
         {
         struct bed *endsBed = NULL;
 	struct bed *upExonBed = NULL, *downExonBed = NULL;
-	struct dyString *dna = newDyString(2*upSeq->size+5);
+	struct dyString *dna = dyStringNew(2*upSeq->size+5);
 	char *tmp = NULL;
 	dyStringPrintf(dna, "%sNNN%s", upSeq->dna, downSeq->dna);
 	if(lifted)
 	    {
             writeOutOverlappingUltra(brainSpConsDnaOut, brainSpConsBedOut,
 				     chrom, chromStart, chromEnd, strand);
 	    }
 	faWriteNext(brainSpDnaUpOut, upSeq->name, upSeq->dna, upSeq->size);
 	bedTabOutN(upSeqBed, 6, brainSpBedUpOut);
 	vmAddVal(brainSpecificValues, skipPSet, "upSeq", upSeq->dna);
 
 	faWriteNext(brainSpDnaDownOut, downSeq->name, downSeq->dna, downSeq->size);
 	bedTabOutN(downSeqBed, 6, brainSpBedDownOut);
 	vmAddVal(brainSpecificValues, skipPSet, "downSeq", downSeq->dna);
 
@@ -3573,31 +3573,31 @@
 }
 
 void doControlStats(struct altEvent *event)
 /* Calculate control stats for control events. */
 {
 struct splice *splice = event->splice;
 struct path *path = event->altPathList->path;
 int chromStart = 0, chromEnd = 0;
 char strand;
 char *chrom;
 int vertIx = 0;
 int *verts = NULL;
 int vC = path->vCount;
 int *vPos = splice->vPositions;
 unsigned char *vTypes = splice->vTypes;
-struct dyString *name = newDyString(128);
+struct dyString *name = dyStringNew(128);
 for(vertIx = 0; vertIx < vC - 1; vertIx++)
     {
     if(isHardExon(vTypes, vertIx, vertIx+1))
 	{
 	char *startChrom = cloneString(path->tName);
 	char *endChrom = cloneString(path->tName);
 	char *cassChrom = cloneString(path->tName);
 	int intStart = vPos[vertIx == 0 ? path->upV : vertIx-1];
 	int dummy = 0;
 	int chromStart = vPos[vertIx];
 	int chromEnd = vPos[vertIx+1];
 	int intEnd = vPos[vertIx+1 == vC - 1 ? path->downV : vertIx+2];
 	char strand = splice->strand[0];
 	boolean lifted = TRUE;
 	dyStringClear(name);
@@ -3896,31 +3896,31 @@
 char *name = optionVal("tissueSpecific", NULL);
 int i = 0;
 AllocArray(tissueSpecificCounts, tissueCount);
 for(i = 0; i < tissueCount; i++)
     {
     AllocArray(tissueSpecificCounts[i], 20);
     }
 tissueSpecificOut = mustOpen(name, "w");
 }
 
 void initBrainSpecific()
 /* Open up the files for brain specific isoforms and dna. */
 {
 struct bindSite *bs = NULL;
 char *prefix = optionVal("brainSpecific", NULL);
-struct dyString *file = newDyString(strlen(prefix)+10);
+struct dyString *file = dyStringNew(strlen(prefix)+10);
 char *useDb = newDb;
 brainSpecificStrict = optionExists("brainSpecificStrict");
 brainSpecificValues = newValuesMat(400,15);
 AllocArray(brainSpecificCounts, altMutExclusive + 1);
 
 if(bindSiteCount > 0)
     {
     AllocArray(brainSpecificMotifUpCounts, bindSiteCount);
     AllocArray(brainSpecificMotifDownCounts, bindSiteCount);
     AllocArray(brainSpecificMotifInsideCounts, bindSiteCount);
     }
 
 dyStringClear(file);
 dyStringPrintf(file, "%s.path.bed", prefix);
 brainSpPathBedOut = mustOpen(file->string, "w");
@@ -3998,31 +3998,31 @@
 for(i = 0; i < dM->colCount; i++)
     {
     fprintf(out, "\t%s", dM->colNames[i]);
     }
 fprintf(out, "\n");
 }
 
 void initRatioStats(struct dMatrix *intenM)
 /* Setupt a file to output ratio statistics to. */
 {
 int i = 0;
 char *outputRatioStats = optionVal("outputRatioStats", NULL);
 struct dyString *buff = NULL;
 assert(outputRatioStats);
 assert(intenM);
-buff = newDyString(strlen(outputRatioStats)+30);
+buff = dyStringNew(strlen(outputRatioStats)+30);
 ratioStatOut = mustOpen(outputRatioStats, "w");
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.skip.intensity", outputRatioStats);
 ratioSkipIntenOut = mustOpen(buff->string, "w");
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.inc.intensity", outputRatioStats);
 ratioIncIntenOut = mustOpen(buff->string, "w");
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.gene.prob", outputRatioStats);
 ratioProbOut = mustOpen(buff->string, "w");
 
 dyStringClear(buff);
@@ -4270,31 +4270,31 @@
 if(differentString(buff, "0.5990734"))
     return FALSE;
 
 result = gsl_cdf_chisq_P(-2*(log(.8)+log(.8)),4);
 safef(buff, sizeof(buff), "%.8f", result);
 if(differentString(buff, "0.07437625"))
     return FALSE;
 return TRUE;
 }
 
 boolean testPathContains(struct unitTest *test)
 /* Test the path contains block functionality. */
 {
 struct splice *ndr2 = ndr2CassTest();
 struct path *skipPath = NULL, *incPath = NULL;
-struct dyString *error = newDyString(128);
+struct dyString *error = dyStringNew(128);
 boolean result = TRUE, currentResult = TRUE;
 skipPath = ndr2->paths;
 incPath = ndr2->paths->next;
 
 if(pathContainsIntron(ndr2, skipPath, "chr14", 43771385+15, 43772095-15, "-") != TRUE)
     currentResult = FALSE;
 if(pathContainsIntron(ndr2, skipPath, "chr14", 43771385+15, 43771715-15, "-") != FALSE)
     currentResult = FALSE;
 if(pathContainsIntron(ndr2, skipPath, "chr14", 43771727+15, 43772095-15, "-") != FALSE)
     currentResult = FALSE;
 if(currentResult == FALSE)
     {
     dyStringPrintf(error, "Problem with placing introns on skip path, ");
     result = FALSE;
     }
@@ -4337,31 +4337,31 @@
     }
 
 test->errorMsg = cloneString(error->string);
 dyStringFree(&error);
 return result;
 }
 
 boolean testPathContainsBed(struct unitTest *test)
 /* Test to see if a path contains the right stuff. */
 {
 struct splice *ndr2 = ndr2CassTest();
 struct bed *bedList = ndr2BedTest(), *bed = NULL;
 /* 1 include, 2 skip, 3 include, 4 gene. */
 struct path *skipPath = NULL, *incPath = NULL;
 boolean result = TRUE;
-struct dyString *error = newDyString(128);
+struct dyString *error = dyStringNew(128);
 skipPath = ndr2->paths;
 incPath = ndr2->paths->next;
 
 /* First include. */
 bed = bedList;
 if(pathContainsBed(ndr2, skipPath, bed, TRUE) != FALSE)
     {
     result = FALSE;
     dyStringPrintf(error, "Matching include bed to skip, ");
     }
 if(pathContainsBed(ndr2, incPath, bed, TRUE) != TRUE)
     {
     result = FALSE;
     dyStringPrintf(error, "Not matching include bed to include, ");
     }
@@ -4446,31 +4446,31 @@
 altPath->expVals[0] = intenM->matrix[0];
 altPath->expVals[1] = intenM->matrix[2];
 AllocArray(altPath->pVals, altPath->probeCount);
 altPath->pVals[0] = probM->matrix[0];
 altPath->pVals[1] = probM->matrix[2];
 slAddHead(&event->altPathList, altPath);
 
 slReverse(&event->altPathList);
 return event;
 }
 
 boolean testAltPathProbesExpressed(struct unitTest *test)
 /* Test to see if presense abs software is calling. */
 {
 struct altEvent *event = setupNdr2AltEvent();
-struct dyString *error = newDyString(128);
+struct dyString *error = dyStringNew(128);
 double expression = 0;
 boolean result = TRUE;
 useMaxProbeSet = TRUE;
 if(altPathProbesExpressed(event, event->altPathList->next, 1, 0, &expression) != FALSE)
     {
     result = FALSE;
     dyStringPrintf(error, "Max probe set calling false positive, ");
     }
 if(altPathProbesExpressed(event, event->altPathList, 0, 3, &expression) != TRUE)
     {
     result = FALSE;
     dyStringPrintf(error, "Max probe set calling positive false, ");
     }
 
 useMaxProbeSet = FALSE;
@@ -4486,31 +4486,31 @@
 }
 
 boolean sameDouble(double d1, double d2)
 /* Check to see if these are the same doubles to 6 sig digits. */
 {
 char buff1[128], buff2[128];
 safef(buff1, sizeof(buff1), "%.6f", d1);
 safef(buff2, sizeof(buff2), "%.6f", d2);
 return sameString(buff1, buff2);
 }
 
 boolean testExpressionRatio(struct unitTest *test)
 /* Test to see if the ratios are calculated properly for expresionRatio() */
 {
 struct altEvent *event = setupNdr2AltEvent();
-struct dyString *error = newDyString(128);
+struct dyString *error = dyStringNew(128);
 double expression = 0;
 boolean result = TRUE;
 boolean current = FALSE;
 struct altPath *skipPath = event->altPathList;
 struct altPath *incPath = event->altPathList->next;
 double tmpThresh = presThresh;
 presThresh = absThresh;
 
 current = sameDouble(expressionRatio(event, skipPath, incPath, 0), 1);
 result &= unitTestFunct(test, current, error, "Averaging");
 
 current = sameDouble(expressionRatio(event, skipPath, incPath, 2), 2);
 result &= unitTestFunct(test, current, error, "Low expressed");
 
 current = sameDouble(expressionRatio(event, skipPath, incPath, 3), .5);
@@ -4647,31 +4647,31 @@
     fprintf(stdout, "Failed tests:\n");
     for(test = failed; test != NULL; test = test->next)
 	{
 	fprintf(stdout, "%-40s\tFAILED\t%s\n", test->description,
 		test->errorMsg == NULL ? "" : test->errorMsg);
 	}
     exit(1);
     }
 }
 
 void initCassetteBedsOut()
 {
 struct dyString *buff = NULL;
 char *prefix = optionVal("cassetteBeds", NULL);
 assert(prefix);
-buff = newDyString(strlen(prefix)+20);
+buff = dyStringNew(strlen(prefix)+20);
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.altExpressed.bed", prefix);
 altCassetteBedOut = mustOpen(buff->string, "w");
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.expressed.bed", prefix);
 expressedCassetteBedOut = mustOpen(buff->string, "w");
 
 dyStringClear(buff);
 dyStringPrintf(buff, "%s.notExpressed.bed", prefix);
 notExpressedCassetteBedOut = mustOpen(buff->string, "w");
 }
 
 void initNotHumanCassettes()