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/protein/lib/domains.c src/hg/protein/lib/domains.c
index 0ae2b4f..0747887 100644
--- src/hg/protein/lib/domains.c
+++ src/hg/protein/lib/domains.c
@@ -8,31 +8,31 @@
 #include "hash.h"
 #include "linefile.h"
 #include "dystring.h"
 #include "spDb.h"
 #include "hdb.h"
 #include "pbTracks.h"
 
 
 char *samGenomeDb(char *proteinId)
 /* Determin if a protein belongs to a genome DB that has SAM results */
 /* This function will be updated as SAM applies to more genomes */
 {
 char condStr[128];
 char *taxon;
 
-sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", proteinId);
+sqlSafef(condStr, sizeof(condStr), "acc='%s'", proteinId);
 taxon = sqlGetField(UNIPROT_DB_NAME, "accToTaxon", "taxon", condStr);
 if (taxon == NULL) return(NULL);
 
 if (sameWord(taxon, "4932")) 
     {
     return(strdup("sacCer1"));
     }
 else
     {
     return(NULL);
     }
 }
 
 void modBaseAnchor(char *swissProtAcc)
 /* Print out anchor to modBase. */
@@ -42,31 +42,31 @@
 
 void domainsPrint(struct sqlConnection *spConn, char *swissProtAcc)
 /* Print out protein domains. */
 {
 struct slName *el, *list;
 char *samDb;
 char condStr[128];
 char *parentId;
 char *kgId = NULL;
 
 /* Use parent protein ID for domain links */
 
 /* There may be cases that a specific variant may have some domain spliced out */
 /* But, it is better to cover most of them, than none at all */
 
-sqlSafefFrag(condStr, sizeof(condStr), "variant='%s'", swissProtAcc);
+sqlSafef(condStr, sizeof(condStr), "variant='%s'", swissProtAcc);
 parentId = sqlGetField(PROTEOME_DB_NAME, "spVariant", "parent", condStr);
 
 list = spExtDbAcc1List(spConn, parentId, "Interpro");
 if (list != NULL)
     {
     char query[256], **row;
     struct sqlResult *sr;
     hPrintf("<B>InterPro Domains: </B>");
     hPrintf("<A HREF=\"http://www.ebi.ac.uk/interpro/ISpy?mode=single&ac=%s\" TARGET=_blank>",
     	swissProtAcc);
     hPrintf("Graphical view of domain structure</A><BR>\n<UL>");fflush(stdout);
     sqlSafef(query, sizeof(query),
     	"select extAcc1,extAcc2 from extDbRef,extDb"
 	" where extDbRef.acc = '%s'"
 	" and extDb.val = 'Interpro' and extDb.id = extDbRef.extDb"
@@ -75,31 +75,31 @@
     sr = sqlGetResult(spConn, query);
     while ((row = sqlNextRow(sr)) != NULL)
         {
 	hPrintf("<LI><A HREF=\"http://www.ebi.ac.uk/interpro/IEntry?ac=%s\" TARGET=_blank>", row[0]);
 	hPrintf("%s</A> - %s</LI>\n", row[0], row[1]);
 	}
     hPrintf("</UL>\n");
     slFreeList(&list);
     }
 
 if (kgVersion == KG_III)
     {
     struct sqlConnection *hgConn;   /* Connection to genome database. */
     hgConn = sqlConnect(database);
    
-    sqlSafefFrag(condStr, sizeof(condStr), "spId='%s'", swissProtAcc);
+    sqlSafef(condStr, sizeof(condStr), "spId='%s'", swissProtAcc);
     kgId = sqlGetField(database, "kgXref", "kgId", condStr);
    
     /* Do Pfam domains here. */
     list = NULL;
     if (kgId != NULL) list = getPfamDomainList(hgConn, kgId);
     if (list != NULL)
     	{
     	hPrintf("<B>Pfam Domains:</B><BR>");
     	for (el = list; el != NULL; el = el->next)
 	    {
 	    char query[256];
 	    char *description;
 	    sqlSafef(query, sizeof(query), 
 	          "select description from %s.pfamDesc where pfamAC='%s'", database, el->name);
 	    description = sqlQuickString(hgConn, query);