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/geneBounds/clusterRna/clusterRna.c src/hg/geneBounds/clusterRna/clusterRna.c
index f51cc82..1f348d9 100644
--- src/hg/geneBounds/clusterRna/clusterRna.c
+++ src/hg/geneBounds/clusterRna/clusterRna.c
@@ -545,31 +545,33 @@
 int count = 0;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     hashAdd(hash, row[0], NULL);
     ++count;
     }
 sqlFreeResult(&sr);
 verbose(2, "%d match %s\n", count, query);
 return hash;
 }
 
 
 struct hash *hashRefSeq(struct sqlConnection *conn)
 /* Get list of all RefSeq mRNAs */
 {
-return hashRow0(conn, NOSQLINJ "select mrnaAcc from refLink");
+char query[1024];
+sqlSafef(query, sizeof query,  "select mrnaAcc from refLink");
+return hashRow0(conn, query);
 }
 
 struct hash *wildHash(struct sqlConnection *conn, char *table, char *pattern)
 /* Read an id/name table, and return hash keyed by id
  * for all members that match pattern. */
 {
 char query[256];
 sqlSafef(query, sizeof query, "select id from %s where name like '%s'", table, pattern);
 return hashRow0(conn, query);
 }
 
 struct hash *hashMa(struct ggMrnaAli *maList)
 /* Return hash of ma's keyed by rna accession. */
 {
 struct ggMrnaAli *ma;
@@ -751,31 +753,33 @@
 struct hash *refSeqHash = hashRefSeq(conn);
 struct hash *mgcEstHash = newHash(20);
 struct hash *mgcRnaHash = newHash(0);
 struct hash *rnaHash = newHash(0);
 struct hash *estAuthorHash = wildHash(conn, "author", "NIH-MGC%");
 struct hash *rnaAuthorHash = wildHash(conn, "author", "Strausberg,R.");
 struct sqlResult *sr = NULL;
 char **row=NULL;
 char *mgcOutFile = NULL;
 int maxPicks = optionInt("mgcNumPicks", 10);     /* How many picks to make. */
 int maxDistance = optionInt("mgcMaxDist", 100);  /* Max distance allowed from 5' end to allow. */
 struct binElement *list = binKeeperFindSorted(bins, 0, chromSize);
 
 /* Read mRNA table and split into hashes. */
 verbose(2, "Scanning mrna table\n");
-sr = sqlGetResult(conn, NOSQLINJ "select acc,type,author from mrna");
+char query[1024];
+sqlSafef(query, sizeof query, "select acc,type,author from mrna");
+sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     char *acc = row[0], *type = row[1], *author = row[2];
     if (sameString(type, "EST"))
         {
 	if (hashLookup(estAuthorHash, author))
 	    hashAdd(mgcEstHash, acc, NULL);
 	}
     else
         {
 	if (hashLookup(rnaAuthorHash, author))
 	    hashAdd(mgcRnaHash, acc, NULL);
 	else
 	    hashAdd(rnaHash, acc, NULL);
 	}