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/intronSizes/intronSizes.c src/hg/intronSizes/intronSizes.c
index bfa1079..f9e3fe0 100644
--- src/hg/intronSizes/intronSizes.c
+++ src/hg/intronSizes/intronSizes.c
@@ -1,102 +1,102 @@
 /* intronSizes - Output list of intron sizes.. */
 
 /* 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 "linefile.h"
 #include "dystring.h"
 #include "hash.h"
 #include "cheapcgi.h"
 #include "jksql.h"
 #include "hdb.h"
 #include "genePred.h"
 
 
 char *chromName;
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "intronSizes - Output list of intron sizes.\n" 
   "usage:\n"
   "   intronSizes database geneTable\n"
   "options:\n"
   "   -chrom=chrN - restrict to a particular chromosome\n"
   "   -withUtr - restrict to genes with UTR regions\n"
   );
 }
 
 void genePredIntrons(struct genePred *gp, struct bed **bedList)
 /* get list of introns (bed format) for a genePred */
 /* append list of introns to bedList */
 {
 int exonIx=1;
 struct bed *bed = NULL;
 
 for (exonIx=1; exonIx < gp->exonCount; ++exonIx)
     {
     int intronStart = gp->exonEnds[exonIx-1];
     int intronEnd = gp->exonStarts[exonIx];
     if (intronEnd > intronStart)
         {
         AllocVar(bed);
         bed->chrom = cloneString(gp->chrom);
         bed->chromStart = intronStart;
         bed->chromEnd = intronEnd;
         bed->name = cloneString(gp->name);
         bed->score = intronEnd-intronStart;
         bed->strand[0] = gp->strand[0];
         bed->strand[1] = gp->strand[1];
         slAddHead(bedList, bed);
         }
     }
 }
 
 void intronSizes(char *database, char *table)
 /* intronSizes - Output list of intron sizes.. */
 {
-struct dyString *query = newDyString(1024);
+struct dyString *query = dyStringNew(1024);
 struct sqlConnection *conn;
 struct sqlResult *sr;
 char **row;
 struct genePred *gp;
 int rowOffset;
 struct bed *bedList = NULL, *bed = NULL;
 
 hSetDb(database);
 rowOffset = hOffsetPastBin(NULL, table);
 conn = hAllocConn(database);
 sqlDyStringPrintf(query, "select * from %s", table);
 if (chromName != NULL)
-    dyStringPrintf(query, " where chrom = '%s'", chromName);
+    sqlDyStringPrintf(query, " where chrom = '%s'", chromName);
 if (cgiBoolean("withUtr"))
     {
-    dyStringPrintf(query, " %s txStart != cdsStart", 
+    sqlDyStringPrintf(query, " %s txStart != cdsStart", 
         (chromName == NULL ? "where" : "and"));
     }
 sr = sqlGetResult(conn, query->string);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     gp = genePredLoad(row+rowOffset);
     genePredIntrons(gp, &bedList);
     slReverse(&bedList);
     for (bed = bedList ; bed != NULL ; bed=bed->next)
         bedTabOutN(bed,6, stdout);
     bedFreeList(&bedList);
     genePredFree(&gp);
     }
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 cgiSpoof(&argc, argv);
 chromName = cgiOptionalString("chrom");
 if (argc != 3)
     usage();
 intronSizes(argv[1], argv[2]);
 return 0;
 }