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/encode3/eap/eapAddStep/eapAddStep.c src/hg/encode3/eap/eapAddStep/eapAddStep.c
index e719d36..34f0fe5 100644
--- src/hg/encode3/eap/eapAddStep/eapAddStep.c
+++ src/hg/encode3/eap/eapAddStep/eapAddStep.c
@@ -211,83 +211,83 @@
 int outCount = commaSepCount(init->outputTypes);
 matchCount = commaSepCount(init->outputFormats);
 if (outCount != matchCount)
     errAbort("outputTypes has %d elements but outputFormats has %d in step %s", 
 	    outCount, matchCount, init->name);
 matchCount = commaSepCount(init->outputNamesInTempDir);
 if (outCount != matchCount)
     errAbort("outputTypes has %d elements but outputNamesInTempDir has %d in step %s", 
 	    outCount, matchCount, init->name);
 matchCount = commaSepCount(init->outputDescriptions);
 if (outCount != matchCount)
     errAbort("outputTypes has %d elements but outputDescriptions has %d in step %s", 
 	    outCount, matchCount, init->name);
 
 struct dyString *query = dyStringNew(0);
-dyStringPrintf(query, "select count(*) from eapStep where name='%s'", init->name);
+sqlDyStringPrintf(query, "select count(*) from eapStep where name='%s'", init->name);
 int existingCount = sqlQuickNum(conn, query->string);
 if (existingCount > 0)
     {
     warn("%s already exists in eapStep", init->name);
     dyStringFree(&query);
     return;
     }
 
 /* Parse out software part and make sure that all pieces are there. */
 char **softwareArray;
 int softwareCount;
 sqlStringDynamicArray(init->software, &softwareArray, &softwareCount);
 unsigned softwareIds[softwareCount];
 int i;
 for (i=0; i<softwareCount; ++i)
     {
     char *name = softwareArray[i];
     dyStringClear(query);
-    dyStringPrintf(query, "select id from eapSoftware where name='%s'", name);
+    sqlDyStringPrintf(query, "select id from eapSoftware where name='%s'", name);
     unsigned softwareId = sqlQuickNum(conn, query->string);
     if (softwareId == 0)
         errAbort("Software %s doesn't exist by that name in eapSoftware", name);
     softwareIds[i] = softwareId;
     }
 
 /* Make step record. */
 dyStringClear(query);
-dyStringAppend(query,
+sqlDyStringPrintf(query,
 	"insert eapStep (name,cpusRequested,description,"
         " inCount,inputTypes,inputFormats,inputDescriptions,"
 	" outCount,outputNamesInTempDir,outputTypes,outputFormats,outputDescriptions)"
 	" values (");
-dyStringPrintf(query, "'%s',", init->name);
-dyStringPrintf(query, "%d,", init->cpusRequested);
-dyStringPrintf(query, "\"%s\",", init->description);
-dyStringPrintf(query, "%d,", inCount);
-dyStringPrintf(query, "'%s',", init->inputTypes);
-dyStringPrintf(query, "'%s',", init->inputFormats);
-dyStringPrintf(query, "\"%s\",", init->inputDescriptions);
-dyStringPrintf(query, "%d,", outCount);
-dyStringPrintf(query, "'%s',", init->outputNamesInTempDir);
-dyStringPrintf(query, "'%s',", init->outputTypes);
-dyStringPrintf(query, "'%s',", init->outputFormats);
-dyStringPrintf(query, "\"%s\"", init->outputDescriptions);
-dyStringPrintf(query, ")");
+sqlDyStringPrintf(query, "'%s',", init->name);
+sqlDyStringPrintf(query, "%d,", init->cpusRequested);
+sqlDyStringPrintf(query, "\"%s\",", init->description);
+sqlDyStringPrintf(query, "%d,", inCount);
+sqlDyStringPrintf(query, "'%s',", init->inputTypes);
+sqlDyStringPrintf(query, "'%s',", init->inputFormats);
+sqlDyStringPrintf(query, "\"%s\",", init->inputDescriptions);
+sqlDyStringPrintf(query, "%d,", outCount);
+sqlDyStringPrintf(query, "'%s',", init->outputNamesInTempDir);
+sqlDyStringPrintf(query, "'%s',", init->outputTypes);
+sqlDyStringPrintf(query, "'%s',", init->outputFormats);
+sqlDyStringPrintf(query, "\"%s\"", init->outputDescriptions);
+sqlDyStringPrintf(query, ")");
 sqlUpdate(conn, query->string);
 
 /* Make software/step associations. */
 for (i=0; i<softwareCount; ++i)
     {
     dyStringClear(query);
-    dyStringPrintf(query, "insert eapStepSoftware (step,software) values ('%s','%s')",
+    sqlDyStringPrintf(query, "insert eapStepSoftware (step,software) values ('%s','%s')",
 	    init->name, softwareArray[i]);
     sqlUpdate(conn, query->string);
     }
 
 
 /* Force step version stuff to be made right away */
 eapCurrentStepVersion(conn, init->name);
 
 /* Clean up. */
 dyStringFree(&query);
 freez(&softwareArray[0]);
 freez(&softwareArray);
 }
 
 void eapAddStep(char *pattern)