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/cgilib/transMapGene.c src/hg/cgilib/transMapGene.c
index 45e0802..2d54822 100644
--- src/hg/cgilib/transMapGene.c
+++ src/hg/cgilib/transMapGene.c
@@ -1,28 +1,25 @@
 /* transMapGene.c was originally generated by the autoSql program, which also 
  * generated transMapGene.h and transMapGene.sql.  This module links the database and
  * the RAM representation of objects. */
 
 #include "common.h"
 #include "linefile.h"
 #include "dystring.h"
 #include "jksql.h"
 #include "transMapGene.h"
 
-char *transMapGeneCommaSepFieldNames4 = "id,cds,db,geneName";   // previous version without geneId column
-char *transMapGeneCommaSepFieldNames = "id,cds,db,geneName,geneId";
-
 void transMapGeneStaticLoad(char **row, struct transMapGene *ret)
 /* Load a row from transMapGene table into ret.  The contents of ret will
  * be replaced at the next call to this function. */
 {
 
 ret->id = row[0];
 ret->cds = row[1];
 safecpy(ret->db, sizeof(ret->db), row[2]);
 ret->geneName = row[3];
 ret->geneId = row[4];
 }
 
 struct transMapGene *transMapGeneLoad(char **row)
 /* Load a transMapGene from row fetched with select * from transMapGene
  * from database.  Dispose of this with transMapGeneFree(). */
@@ -146,23 +143,23 @@
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */
 
 struct transMapGene *transMapGeneQuery(struct sqlConnection *geneConn,
                                        char *table, char *srcDb, char *srcId)
 /* load a single transMapSrc object for an srcDb and srcId from a table,
  * or return NULL if not found */
 {
 /* geneId field was added after original table definition.  Return empty string
  * in query for legacy tables. */
 if (sqlFieldIndex(geneConn, table, "geneId") >= 0)
     return sqlQueryObjs(geneConn, (sqlLoadFunc)transMapGeneLoad,
                         sqlQuerySingle,
-                        "SELECT %-s FROM %s WHERE (db=\"%s\") and (id = \"%s\")",
-                        transMapGeneCommaSepFieldNames, table, srcDb, srcId);
+                        "SELECT id,cds,db,geneName,geneId FROM %s WHERE (db=\"%s\") and (id = \"%s\")",
+                        table, srcDb, srcId);
 else
     return sqlQueryObjs(geneConn, (sqlLoadFunc)transMapGeneLoad,
                         sqlQuerySingle,
-                        "SELECT %-s,\"\" FROM %s WHERE (db=\"%s\") and (id = \"%s\")",
-                        transMapGeneCommaSepFieldNames4, table, srcDb, srcId);
+                        "SELECT id,cds,db,geneName,\"\" FROM %s WHERE (db=\"%s\") and (id = \"%s\")",
+                        table, srcDb, srcId);
 }