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/utils/mutationClassifier/mutationClassifier.c src/hg/utils/mutationClassifier/mutationClassifier.c
index a0de950..c7c2bd4 100644
--- src/hg/utils/mutationClassifier/mutationClassifier.c
+++ src/hg/utils/mutationClassifier/mutationClassifier.c
@@ -581,31 +581,31 @@
 static struct hash *motifHash = NULL;
 struct hashEl *el;
 if(motifHash == NULL)
     motifHash = newHash(0);
 
 if ((el = hashLookup(motifHash, name)))
     {
     if(cacheHit)
         *cacheHit = TRUE;
     return (struct dnaMotif *) el->val;
     }
 else
     {
     char where[256];
     struct sqlConnection *conn = sqlConnect(database);
-    sqlSafefFrag(where, sizeof(where), "name = '%s'", name);
+    sqlSafef(where, sizeof(where), "name = '%s'", name);
     struct dnaMotif *motif = dnaMotifLoadWhere(conn, "transRegCodeMotifPseudoCounts", where);
     hashAdd(motifHash, name, (void *) motif);
     sqlDisconnect(&conn);
     if(cacheHit)
         *cacheHit = FALSE;
     return motif;
     }
 }
 
 static struct genePred *findNearestGene(struct bed *bed, struct genePred *genes, int maxDistance, int *minDistance)
 // return nearest gene (or NULL if none found).
 // minDistance is set to 0 if item is within returned gene, otherwise the distance to txStart or txEnd.
 // Currently inefficient (O(length genes)).
 {
 struct genePred *retVal = NULL;
@@ -703,31 +703,31 @@
     {
     // look for de novo mutations.
     struct dnaMotif *motif = NULL;
     struct slName *motifName, *motifNames = NULL;
     char query[256];
     char where[256];
     struct sqlResult *sr;
     char **row;
     sqlSafef(query, sizeof(query), "select name from %s", motifTable);
     sr = sqlGetResult(conn, query);
     while ((row = sqlNextRow(sr)) != NULL)
         slAddHead(&motifNames, slNameNew(row[0]));
     sqlFreeResult(&sr);
     for(motifName = motifNames; motifName != NULL; motifName = motifName->next)
         {
-        sqlSafefFrag(where, sizeof(where), "name = '%s'", motifName->name);
+        sqlSafef(where, sizeof(where), "name = '%s'", motifName->name);
         motif = dnaMotifLoadWhere(conn, motifTable, where);
         if(motif == NULL)
             errAbort("couldn't find motif '%s'", motifName->name);
         maxMotifLen = max(maxMotifLen, motif->columnCount);
         slAddHead(&motifs, motif);
         }
     slReverse(&motifs);
     }
 
 while(!done)
     {
     struct bed7 *overlapA = NULL;
     struct bed7 *bed, *unusedA = NULL;
     struct genePredStub *overlapB = NULL;
     struct bed7 *snps = NULL;