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/spToProteins/spToProteins.c src/hg/protein/spToProteins/spToProteins.c
index 148bf70..b7ea32e 100644
--- src/hg/protein/spToProteins/spToProteins.c
+++ src/hg/protein/spToProteins/spToProteins.c
@@ -79,47 +79,47 @@
     if (*isCurated == '1')
 	{
 	bioDatabase = 1;
 	}
     else
 	{
 	if (strlen(accession) > 7) 
 	    {
 	    bioDatabase = 3;
 	    }
 	else
 	    {
 	    bioDatabase = 2;
 	    }
 	}
-    sqlSafefFrag(cond_str, sizeof(cond_str), "acc='%s'", accession);
+    sqlSafef(cond_str, sizeof(cond_str), "acc='%s'", accession);
     displayId = sqlGetField(proteinDatabaseName, "displayId", "val", cond_str);
 
     // !!! the divsion field probably should be eliminated later
     // use the simple 1 taxon returned value function for the time being, 
     // could expand into multiple by calling spBinomialNames later 
     taxon = spTaxon(conn3, accession);
 
     taxonList = spTaxons(conn3, accession);
     for (name = taxonList; name != NULL; name = name->next)
 	{
 	fprintf(o3, "%s\t%s\n", displayId, name->name);
 	}
 
-    sqlSafefFrag(cond_str, sizeof(cond_str), "acc='%s'", accession);
+    sqlSafef(cond_str, sizeof(cond_str), "acc='%s'", accession);
     desc = sqlGetField(proteinDatabaseName, "description", "val", cond_str);
-    sqlSafefFrag(cond_str, sizeof(cond_str), "uniProt='%s'", accession);
+    sqlSafef(cond_str, sizeof(cond_str), "uniProt='%s'", accession);
     hugoSymbol = sqlGetField(proteinsDB, "hgnc", "symbol", cond_str);
     hugoDesc = sqlGetField(proteinsDB, "hgnc", "name", cond_str);
     if (hugoSymbol==NULL) hugoSymbol = empty_str;
     if (hugoDesc==NULL)   hugoDesc   = empty_str;
 
     fprintf(o2, "%s\t%s\t%d\t%d\t%d\t%s\t%s\t%s\n", accession, displayId, 
 	   taxon, bioentryId, bioDatabase, desc, hugoSymbol, hugoDesc);
     
     sqlSafef(query, sizeof(query),
 	    "select extAcc1, extDb.val from sp%s.extDb, sp%s.extDbRef where extDbRef.acc='%s' %s",
 	    proteinDataDate, proteinDataDate, accession, "and extDb.id = extDbRef.extDb;"); 
     sr = sqlMustGetResult(conn, query);
     row = sqlNextRow(sr);
     while (row != NULL)
     	{