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/hgGene/pseudoGene.c src/hg/hgGene/pseudoGene.c
index 1de66fe..3926510 100644
--- src/hg/hgGene/pseudoGene.c
+++ src/hg/hgGene/pseudoGene.c
@@ -1,119 +1,119 @@
 /* pseudoGene descriptions. */
 
 /* Copyright (C) 2013 The Regents of the University of California 
  * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
 
 #include "common.h"
 #include "hash.h"
 #include "linefile.h"
 #include "dystring.h"
 #include "spDb.h"
 #include "hdb.h"
 #include "web.h"
 #include "genePred.h"
 #include "bed.h"
 #include "hgGene.h"
 #include "genbank.h"
 
 
 static boolean pseudoGeneExists(struct section *section, 
 	struct sqlConnection *conn, char *geneId)
 /* Return TRUE if mrna  on this one. */
 {
 boolean result;
 
 result = FALSE;
 if (hTableExists(sqlGetDatabase(conn), "ucscRetroInfo"))
     {
     struct sqlResult *sr;
     char **row;
     char query[255];
     sqlSafef(query, sizeof(query),
           "select name from ucscRetroInfo where name='%s' or kgName='%s' or refseq='%s'",
 	  geneId, geneId, geneId);
     sr = sqlGetResult(conn, query);
     if ((row = sqlNextRow(sr)) != NULL) 
     	{
 	result = TRUE;
 	}
 	
     sqlFreeResult(&sr);
     }
 return(result);
 }
 
 static void pseudoGenePrint(struct section *section, 
 	struct sqlConnection *conn, char *geneId)
 /* Print out mrna descriptions annotations. */
 {
 struct sqlResult *sr;
 char **row;
 char condStr[255];
 char *descID, *desc;    
 char *emptyStr;
 char query[255];
 char *name, *chrom, *chromStart, *chromEnd, *refseq, *rtype;
 int  score;
 
 webPrintLinkTableStart();
 webPrintLabelCell("Retro Id");
 webPrintLabelCell("Type");
 webPrintLabelCell("Score ");
 webPrintLabelCell("Genome Location");
 webPrintLabelCell("Description");
 hPrintf("</TR>\n<TR>");
 emptyStr = cloneString("");
 sqlSafef(query, sizeof(query),
       "select distinct name, chrom, chromStart, chromEnd, refseq, type, score from ucscRetroInfo where name='%s' or kgName='%s' or refseq='%s'",
       geneId, geneId, geneId);
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL) 
     {
     name 	= row[0];
     chrom	= row[1];
     chromStart  = row[2];
     chromEnd	= row[3];
     refseq	= row[4];
     rtype	= row[5];
     score	= sqlUnsigned(row[6]);
    
     desc = emptyStr;
-    sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", refseq);
+    sqlSafef(condStr, sizeof(condStr), "acc='%s'", refseq);
     descID= sqlGetField(database, gbCdnaInfoTable, "description", condStr);
     if (descID != NULL)
     	{
-    	sqlSafefFrag(condStr, sizeof(condStr), "id=%s", descID);
+    	sqlSafef(condStr, sizeof(condStr), "id=%s", descID);
     	desc = sqlGetField(database, descriptionTable, "name", condStr);
 	if (desc == NULL) desc = emptyStr;
 	}
    	
     webPrintLinkCellStart();
     hPrintf("<A HREF=\"hgc?g=ucscRetroAli&i=%s\">%s</A>", name, name);
     webPrintLinkCellEnd();
     webPrintLinkCellStart();
     hPrintf("%s ", rtype);
     webPrintLinkCellEnd();
     webPrintLinkCellStart();
     hPrintf("%d ", score);
     webPrintLinkCellEnd();
     webPrintLinkCellStart();
     hPrintf("<A HREF=\"hgTracks?position=%s:%s-%s&ucscRetroAli=pack&hgFind.matches=%s,\">%s:%s-%s</A>",
            chrom, chromStart, chromEnd, name, chrom, chromStart, chromEnd);
     webPrintLinkCellEnd();
     webPrintLinkCellStart();
     hPrintf("%s\n", desc);
     webPrintLinkCellEnd();
     hPrintf("</TR>\n<TR>");
     }
 sqlFreeResult(&sr);
 }
 
 struct section *pseudoGeneSection(struct sqlConnection *conn, 
 	struct hash *sectionRa)
 /* Create pseudoGene section. */
 {
 struct section *section = sectionNew(sectionRa, "pseudoGene");
 section->exists = pseudoGeneExists;
 section->print = pseudoGenePrint;
 return section;
 }