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/spliceProbeVis.c src/hg/altSplice/affySplice/spliceProbeVis.c
index 567e249..e206135 100644
--- src/hg/altSplice/affySplice/spliceProbeVis.c
+++ src/hg/altSplice/affySplice/spliceProbeVis.c
@@ -115,34 +115,34 @@
       skipPSet);
 
 /* Check our little cache. */
 if(altEvent == NULL)      
     altEvent = event = mouseAPSetEventMapLoadByQuery(conn, eventQuery);
 else 
     event = altEvent;
 
 if(event == NULL)
     errAbort("Couldn't find an alternative events for: %s", skipPSet);
 
 assert(query);
 dyStringClear(query);
 sqlDyStringPrintf(query, "select * from %s where ", tableName);
 for(i = 0; i < event->incCount; i++) 
-    dyStringPrintf(query, "name like '%s' or ", event->incPSets[i]);
+    sqlDyStringPrintf(query, "name like '%s' or ", event->incPSets[i]);
 for(i = 0; i < event->geneCount; i++) 
-    dyStringPrintf(query, "name like '%s' or ", event->genePSets[i]);
-dyStringPrintf(query, "name like '%s' order by name;", skipPSet);
+    sqlDyStringPrintf(query, "name like '%s' or ", event->genePSets[i]);
+sqlDyStringPrintf(query, "name like '%s' order by name;", skipPSet);
 hFreeConn(&conn);
 }
 
 void closePlotOutput(struct dyString *script) 
 /* Turn off device. */
 {
 dyStringPrintf(script, "dev.off();\n");
 }
 
 struct dMatrix *dataFromTable(char *tableName, char *query)
 /* Read data from table name with rowname. */
 {
 struct sqlConnection *conn = hAllocConn();
 struct slName *colNames = sqlListFields(conn, tableName);
 struct slName *name = NULL;
@@ -346,31 +346,31 @@
 out = mustOpen(rScript.forCgi, "w");
 fprintf(out, "%s", script->string);
 carefulClose(&out);
 safef(command, sizeof(command), "R --vanilla < %s >& /dev/null ", rScript.forCgi);
 system(command);
 }
 
 
 
 void doMatrixPlot(struct dyString *script, 
 		  char *skipPSet, char *tableName, char *type,
 		  boolean linesOnly)
 /* Print out a matrix plot for a particular table. */
 {
 struct tempName plotFile;
-struct dyString *query = newDyString(256);
+struct dyString *query = dyStringNew(256);
 struct dMatrix *dM = NULL;
 char title[256];
 safef(title, sizeof(title), "%s - %s", altEvent->geneName, type);
 if(cgiBoolean("pdf"))
     makeTempName(&plotFile, "sp", ".pdf");
 else
     makeTempName(&plotFile, "sp", ".png");
 touchBlank(plotFile.forCgi);
 makePlotLink(type, plotFile.forCgi);
 //dyStringPrintf(html, "<img src='%s'><br>\n", plotFile.forCgi);
 constructQueryForEvent(query, skipPSet, tableName);
 dM = dataFromTable(tableName, query->string);
 plotMatrixRows(dM, script, title, plotFile.forCgi, type, linesOnly) ;
 }
 
@@ -383,34 +383,34 @@
 void doProbeSetPVals(struct dyString *script, char *skipPSet)
 /* Plot the p-values. */
 {
 doMatrixPlot(script, skipPSet, "mouseAPSetPval", "PSet (1 - p-val)", FALSE);
 }
 
 void doNormProbes(struct dyString *script, char *skipPSet)
 /* Plot the normalized version of the raw probe values. */
 {
 doMatrixPlot(script, skipPSet, "mouseAProbeNormInten", "Probe Intensity", TRUE);
 }
 
 void doPlots()
 /* Do all the plots. */
 {
-struct dyString *script = newDyString(2048);
-struct dyString *dummy = newDyString(256);
+struct dyString *script = dyStringNew(2048);
+struct dyString *dummy = dyStringNew(256);
 char *skipPSet = cgiUsualString("skipPName", "G7153846@J939317_RC@j_at");
-html = newDyString(1024);
+html = dyStringNew(1024);
 hSetDb("mm5");
 dyStringPrintf(script, "%s", rHeader);
 
 /* Call query once to initialize altEvent. */
 constructQueryForEvent(dummy, skipPSet, "dummy");
 assert(altEvent);
 fprintf(stdout, "<h3>Plots for %s (%s)</h3>\n", altEvent->geneName, skipPSet);
 fflush(stdout);
 /* Probe set plots. */
 doRegressionPlot(script, skipPSet, 
 		 "mouseAEvent_inc_intensity", 
 		 "mouseAEvent_skip_intensity",
 		 "mouseAEvent_gene_prob");
 doProbeSet(script, skipPSet);
 doProbeSetPVals(script, skipPSet);