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/lib/spDb.c src/hg/lib/spDb.c
index dfa231d..3355689 100644
--- src/hg/lib/spDb.c
+++ src/hg/lib/spDb.c
@@ -458,33 +458,33 @@
 struct spFeature *spFeatures(struct sqlConnection *conn, char *acc,
 	int classId, 	/* Feature class ID, 0 for all */
 	int typeId)	/* Feature type ID, 0 for all */
 /* Get feature list.  slFreeList this when done. */
 {
 struct dyString *dy = dyStringNew(0);
 struct spFeature *list = NULL, *el;
 char **row;
 struct sqlResult *sr;
 
 sqlDyStringPrintf(dy, 
 	"select start,end,featureClass,featureType,softEndBits from feature ");
 sqlDyStringPrintf(dy, 
         "where acc = '%s'", acc);
 if (classId != 0)
-    dyStringPrintf(dy, " and featureClass=%d", classId);
+    sqlDyStringPrintf(dy, " and featureClass=%d", classId);
 if (typeId != 0)
-    dyStringPrintf(dy, " and featureType=%d", typeId);
+    sqlDyStringPrintf(dy, " and featureType=%d", typeId);
 sr = sqlGetResult(conn, dy->string);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     AllocVar(el);
     el->start = sqlUnsigned(row[0]);
     el->end = sqlUnsigned(row[1]);
     el->featureClass = sqlUnsigned(row[2]);
     el->featureType = sqlUnsigned(row[3]);
     el->softEndBits = sqlUnsigned(row[4]);
     slAddHead(&list, el);
     }
 sqlFreeResult(&sr);
 dyStringFree(&dy);
 slReverse(&list);
 return list;
@@ -609,50 +609,50 @@
 }
 
 char *newSpDisplayId(char *oldSpDisplayId)
 /* Convert from old Swiss-Prot display ID to new display ID */
 {
 static struct sqlConnection *conn=NULL;
 char condStr[255];
 char *newSpDisplayId;
 
 if (conn==NULL)
     {
     conn = sqlConnect(PROTEOME_DB_NAME);
     if (conn == NULL) return NULL;
     }
     
-sqlSafefFrag(condStr, sizeof(condStr), "oldDisplayId='%s'", oldSpDisplayId);
+sqlSafef(condStr, sizeof(condStr), "oldDisplayId='%s'", oldSpDisplayId);
 newSpDisplayId = sqlGetField(PROTEOME_DB_NAME, "spOldNew", "newDisplayId", condStr);
     
 return(newSpDisplayId);
 }		   
 
 char *oldSpDisplayId(char *newSpDisplayId)
 /* Convert from new Swiss-Prot display ID to old display ID */
 {
 static struct sqlConnection *conn=NULL;
 char condStr[255];
 char *oldSpDisplayId;
 
 if (conn==NULL)
     {
     conn = sqlConnect(PROTEOME_DB_NAME);
     if (conn == NULL) return NULL;
     }
 
-sqlSafefFrag(condStr, sizeof(condStr), "newDisplayId='%s'", newSpDisplayId);
+sqlSafef(condStr, sizeof(condStr), "newDisplayId='%s'", newSpDisplayId);
 oldSpDisplayId = sqlGetField(PROTEOME_DB_NAME, "spOldNew", "oldDisplayId", condStr);
     
 return(oldSpDisplayId);
 }	
 
 char *uniProtFindPrimAcc(char *id)
 /* Return primary accession given an alias. */
 /* The alias could be an accession number, display ID, old display ID, etc. 
  * NULL if not found. */
 {
 static struct sqlConnection *conn=NULL;
 char *acc;
 char query[256];
 
 if (conn==NULL)