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/makeDb/outside/hgKegg2/hgKegg2.c src/hg/makeDb/outside/hgKegg2/hgKegg2.c
index 7e39258..8b5f3ad 100644
--- src/hg/makeDb/outside/hgKegg2/hgKegg2.c
+++ src/hg/makeDb/outside/hgKegg2/hgKegg2.c
@@ -1,86 +1,86 @@
 /* hgKegg2 - creates keggPathway.tab and keggMapDesc.tab files for KG links to KEGG Pathway Map */
 
 /* 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 "hCommon.h"
 #include "hdb.h"
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "hgKegg2 - creates keggPathway.tab and keggMapDesc.tab files for KG links to KEGG Pathway Map"
   "usage:\n"
   "   hgKegg2 kgTempDb roDb\n"
   "      kgTempDb is the KG build temp database name\n"
   "      roDb is the read only genome database name\n"
   "example: hgKegg2 kgMm6ATemp mm6\n");
 }
 
 int main(int argc, char *argv[])
 {
 struct sqlConnection *conn, *conn2, *conn3;
 char query[256], query3[256];
 struct sqlResult *sr, *sr3;
 char **row, **row3;
 FILE *o1, *o2;
 
 char *locusID;	/* LocusLink ID */
 char *refAC;	/* Refseq accession.version */
 char *kgTempDbName, *roDbName; 
 char cond_str[200];
 char *kgID;
 char *mapID;
 char *desc;
 
 if (argc != 3)  usage();
 kgTempDbName    = argv[1];
 roDbName 	= argv[2];
 
 conn = hAllocConn(roDbName);
 conn2= hAllocConn(roDbName);
 conn3= hAllocConn(roDbName);
 
 o1 = fopen("j.dat",  "w");
 o2 = fopen("jj.dat", "w");
     
 sqlSafef(query, sizeof query, "select kgID, refseq from %s.kgXref", roDbName);
 sr = sqlMustGetResult(conn, query);
 row = sqlNextRow(sr);
 while (row != NULL)
     {
     kgID  = row[0];
     refAC = row[1];
 	
-    sqlSafefFrag(cond_str, sizeof cond_str, "refseq='%s'", refAC);
+    sqlSafef(cond_str, sizeof cond_str, "refseq='%s'", refAC);
     locusID = sqlGetField("entrez", "entrezRefProt", "geneID", cond_str);
     if (locusID != NULL)
 	{
         sqlSafef(query3, sizeof query3, "select * from %s.keggList where locusID = '%s'", kgTempDbName, locusID);
         sr3 = sqlGetResult(conn3, query3);
         while ((row3 = sqlNextRow(sr3)) != NULL)
             {
             mapID   = row3[1];
 	    desc    = row3[2];
 	    fprintf(o1, "%s\t%s\t%s\n", kgID, locusID, mapID);fflush(o1);
 	    fprintf(o2, "%s\t%s\n", mapID, desc);
 	    row3 = sqlNextRow(sr3);
             }
         sqlFreeResult(&sr3);
 	}
     row = sqlNextRow(sr);
     }
 
 fclose(o1);
 fclose(o2);
 hFreeConn(&conn);
 hFreeConn(&conn2);
 
 mustSystem("cat j.dat|sort|uniq >keggPathway.tab");
 mustSystem("cat jj.dat|sort|uniq >keggMapDesc.tab");
 mustSystem("rm j.dat");
 mustSystem("rm jj.dat");
 return(0);
 }