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/das/das.c src/hg/das/das.c
index b704ec2..79fb6e4 100644
--- src/hg/das/das.c
+++ src/hg/das/das.c
@@ -304,31 +304,33 @@
 return hashLookup(skips, name) != NULL;
 }
 
 static struct tableDef *getTables()
 /* Get all tables. */
 {
 struct sqlConnection *conn = hAllocConn(database);
 struct hash *hash = newHash(0);
 struct tableDef *tdList = NULL, *td;
 struct sqlResult *sr;
 char **row;
 char *table, *root;
 boolean isSplit, hasBin;
 char chromField[32], startField[32], endField[32];
 
-sr = sqlGetResult(conn, NOSQLINJ "show tables");
+char query[1024];
+sqlSafef(query, sizeof query, "show tables"); 
+sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     table = root = row[0];
     if (hFindFieldsAndBin(database, table, chromField, startField, endField, &hasBin))
 	{
 	isSplit = tableIsSplit(table);
 	if (isSplit)
 	    root = skipOverChrom(table);
 	if (!skipTable(root) && dasableTrack(root))
 	    {
 	    if ((td = hashFindVal(hash, root)) == NULL)
 		{
 		AllocVar(td);
 		slAddHead(&tdList, td);
 		hashAdd(hash, root, td);
@@ -969,31 +971,33 @@
 static void doEntryPoints()
 /* Handle entry points request. */
 {
 struct sqlConnection *conn;
 struct sqlResult *sr;
 char **row;
 struct chromInfo *ci;
 
 normalHeader();
 conn = hAllocConn(database);
 printf("<!DOCTYPE DASEP SYSTEM \"http://www.biodas.org/dtd/dasep.dtd\">\n");
 printf("<DASEP>\n");
 printf("<ENTRY_POINTS href=\"%s\" version=\"7.00\">\n",
 	currentUrl());
 
-sr = sqlGetResult(conn, NOSQLINJ "select * from chromInfo");
+char query[1024];
+sqlSafef(query, sizeof query, "select * from chromInfo");
+sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     ci = chromInfoLoad(row);
     /* "chr"-less chromosome ID for clients such as Ensembl: */
     if (startsWith("chr", ci->chrom))
 	printf(" <SEGMENT id=\"%s\" start=\"%d\" stop=\"%d\" orientation=\"+\" subparts=\"no\">%s</SEGMENT>\n", ci->chrom+3, 1, ci->size, ci->chrom+3);
     else
 	printf(" <SEGMENT id=\"%s\" start=\"%d\" stop=\"%d\" orientation=\"+\" subparts=\"no\">%s</SEGMENT>\n", ci->chrom, 1, ci->size, ci->chrom);
     chromInfoFree(&ci);
     }
 
 printf("</ENTRY_POINTS>\n");
 printf("</DASEP>\n");
 }