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/lib/chainNetDbLoad.c src/hg/lib/chainNetDbLoad.c
index 5b2fe16..1528c2f 100644
--- src/hg/lib/chainNetDbLoad.c
+++ src/hg/lib/chainNetDbLoad.c
@@ -293,62 +293,62 @@
 lmCleanup(&lm);
 return chain;
 }
 
 static struct chain *chainLoadIdSome(char *database, char *track, char *chrom, 
         int start, int end, int id, boolean loadAll)
 /* Load some or all of chain. */
 {
 struct sqlConnection *conn;
 struct sqlResult *sr;
 char **row;
 char table[HDB_MAX_TABLE_STRING];
 boolean hasBin;
 struct chain *chain;
 char query[256];
-struct dyString *dy = newDyString(128);
+struct dyString *dy = dyStringNew(128);
 
 /* Load chain header. */
 if (!hFindSplitTable(database, chrom, track, table, sizeof table, &hasBin))
    errAbort("%s table is not in %s", track, database);
 conn = sqlConnect(database);
 sqlSafef(query, sizeof(query),
 	"select * from %s where id = %d", table, id);
 sr = sqlGetResult(conn, query);
 if ((row = sqlNextRow(sr)) == NULL)
     errAbort("chain %d is not in %s", id, table);
 chain = chainHeadLoad(row+hasBin);
 sqlFreeResult(&sr);
 
 /* Load links. */
 if (loadAll)
     {
     sqlDyStringPrintf(dy, 
 	 "select * from %sLink where chainId = %d", table, id);
     }
 else
     {
     sqlDyStringPrintf(dy, 
 	 "select * from %sLink where ",table );
     hAddBinToQuery(start, end, dy);
     sqlDyStringPrintf(dy," chainId = %d and tStart < %d and tEnd > %d", id, end, start);
     }
 sr = sqlGetResult(conn, dy->string);
 chainLinkAddResult(sr, hasBin, chain);
 sqlFreeResult(&sr);
 sqlDisconnect(&conn);
-freeDyString(&dy);
+dyStringFree(&dy);
 return chain;
 }
 
 struct chain *chainLoadIdRange(char *database, char *track, char *chrom, 
 	int start, int end, int id)
 /* Load parts of chain of given ID from database.  Note the chain header
  * including score, tStart, tEnd, will still reflect the whole chain,
  * not just the part in range.  However only the blocks of the chain
  * overlapping the range will be loaded. */
 {
 return chainLoadIdSome(database, track, chrom, start, end, id, FALSE);
 }
 
 struct chain *chainLoadId(char *database, char *track, char *chrom, int id)
 /* Load chain of given ID from database. */