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/mrnaDescriptions.c src/hg/hgGene/mrnaDescriptions.c index 5a04ee3..aef358b 100644 --- src/hg/hgGene/mrnaDescriptions.c +++ src/hg/hgGene/mrnaDescriptions.c @@ -1,101 +1,101 @@ /* mRNA 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 "genePred.h" #include "bed.h" #include "hgGene.h" #include "genbank.h" static boolean mrnaDescriptionsExists(struct section *section, struct sqlConnection *conn, char *geneId) /* Return TRUE if mrna on this one. */ { struct psl *list = NULL; if (hTableExists(sqlGetDatabase(conn), "all_mrna")) { struct sqlResult *sr; char **row; struct psl *psl; int rowOffset; char extra[64]; - safef(extra, sizeof(extra), "strand='%c'", curGenePred->strand[0]); + sqlSafef(extra, sizeof(extra), "strand='%c'", curGenePred->strand[0]); sr = hRangeQuery(conn, "all_mrna", curGeneChrom, curGeneStart, curGeneEnd, extra, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { psl = pslLoad(row+rowOffset); slAddHead(&list, psl); } slReverse(&list); section->items = list; } return slCount(list) > 0; } static int basesShared(struct genePred *gp, struct psl *psl) /* Return number of bases a&b share. */ { int intersect = 0; int i, blockCount = psl->blockCount; int s,e; for (i=0; i<blockCount; ++i) { s = psl->tStarts[i]; e = s + psl->blockSizes[i]; if (psl->strand[1] == '-') reverseIntRange(&s, &e, psl->tSize); intersect += gpRangeIntersection(gp, s, e); } return intersect; } static void mrnaDescriptionsPrint(struct section *section, struct sqlConnection *conn, char *geneId) /* Print out mrna descriptions annotations. */ { struct psl *psl, *pslList = section->items; for (psl = pslList; psl != NULL; psl = psl->next) { if (basesShared(curGenePred, psl) > 12) /* Filter out possible little noisy flecks. */ { char query[512]; char *description; sqlSafef(query, sizeof(query), "select d.name from %s g,%s d" " where g.acc='%s' and g.description = d.id" , gbCdnaInfoTable, descriptionTable, psl->qName); description = sqlQuickString(conn, query); if (description != NULL) { char *url = "https://www.ncbi.nlm.nih.gov/entrez/query.fcgi" "?cmd=Search&db=Nucleotide&term=%s&doptcmdl=GenBank" "&tool=genome.ucsc.edu"; hPrintf("<A HREF=\""); hPrintf(url, psl->qName); hPrintf("\" TARGET=_blank>"); hPrintf("%s</A> - ", psl->qName); hPrintf("%s<BR>", description); } freeMem(description); } } } struct section *mrnaDescriptionsSection(struct sqlConnection *conn, struct hash *sectionRa) /* Create mrnaDescriptions section. */ { struct section *section = sectionNew(sectionRa, "mrnaDescriptions"); section->exists = mrnaDescriptionsExists; section->print = mrnaDescriptionsPrint; return section; }