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/mouseStuff/chainCleaner/chainCleaner.c src/hg/mouseStuff/chainCleaner/chainCleaner.c index 993b08c..63b787a 100644 --- src/hg/mouseStuff/chainCleaner/chainCleaner.c +++ src/hg/mouseStuff/chainCleaner/chainCleaner.c @@ -1098,31 +1098,31 @@ slAddHead(&netList, net); } slReverse(&netList); lineFileClose(&lf); verbose(1, "DONE\n\n"); /* we need a init and allocate a few hashes and arrays. Arrays are used with net depth being the index to keep track of which chain and which gap we currently have at each depth */ verbose(1, "1.2 get fills/gaps from %s ...\n", netFile); chainId2Count = newHash(0); /* counts how often we see a chain ID at depth > 1 */ fillGapInfoHash = newHash(0); /* Hash keyed chainId, stores a list of fillGapInfo structs */ AllocArray(depth2gap, maxNetDepth); /* information about the current gap at each depth (hash key) */ for (i=0; i<maxNetDepth; i++) - depth2gap[i] = newDyString(200); + depth2gap[i] = dyStringNew(200); AllocArray(depth2chainId, maxNetDepth); /* information about which chain ID is the fill at each depth (hash key) */ /* now parse all the nets, fill the fillGapInfo struct for every chain at depth>1 */ for (net = netList; net != NULL; net = net->next) { if (onlyThisChr != NULL && (! sameString(onlyThisChr, net->name))) continue; verbose(2, "\tparse net %s of size %d\n", net->name, net->size); tName = net->name; /* need to keep track of the current target chrom/scaffold */ parseFill(net->fillList, 1, tName); } verbose(1, "DONE\n\n"); /* parse the nets once and add all aligning blocks of a net that do not have children (NOTE: they can span gaps) to the genomeRangeTree We will use this in isBrokenByAnotherHigherScoringChain() to check if the broken chain is also broken by another even-higher-scoring chain */ @@ -1149,31 +1149,31 @@ /* get valid breaks */ verbose(1, "1.4 get valid breaks ...\n"); breakHash = newHash(0); chainId2IsOfInterest = newHash(0); hashTraverseEls(chainId2Count, getValidBreaks); verbose(1, "DONE\n"); if (verboseLevel() >= 3) { verbose(3, "\n\nVERBOSE OUTPUT: Here are all the breaks (printAllBreaks())\n"); printAllBreaks(); } /* free arrays that hold values per depth */ for (i=0; i<maxNetDepth; i++) - freeDyString(&depth2gap[i]); + dyStringFree(&depth2gap[i]); freez(&depth2gap); freez(&depth2chainId); genomeRangeTreeFree(&rangeTreeAliBlocks); } /**************************************************************** sum up the bases in aligning blocks of the chain ****************************************************************/ int getSubChainBases(struct chain *chain) { struct cBlock *b; int numBases = 0; for (b = chain->blockList; b != NULL; b = b->next) { numBases += (b->tEnd - b->tStart); } @@ -1626,31 +1626,31 @@ break; } } } hashElFreeList(&helList); } /**************************************************************** net the chains if no net file is given Netting will be done by chainNet minScore=0 followed by non-nested net filtering with a minscore of 3000 A tempfile will be created for the nets ****************************************************************/ void netInputChains (char *chainFile) { int fd = 0, retVal = 0; - struct dyString* cmd = newDyString(500); + struct dyString* cmd = dyStringNew(500); char netFile[200]; /* must have the t/q sizes */ if (tSizes == NULL) errAbort("You must specifiy -tSizes /dir/to/target/chrom.sizes if you do not provide a net file with -net in.net\n"); if (qSizes == NULL) errAbort("You must specifiy -qSizes /dir/to/query/chrom.sizes if you do not provide a net file with -net in.net\n"); /* create a unique tempFile (and close it because mkstemp opens it */ safef(netFile, sizeof(netFile), "tmp.chainCleaner.XXXXXXX.net"); if ((fd = mkstemps(netFile,4)) < 0 ) { errAbort("ERROR: cannot create a tempfile for netting the chain file: %s\n",strerror(errno)); } else { verbose(1, "\t\ttempfile for netting: %s\n", netFile); close(fd); @@ -1684,31 +1684,31 @@ /* ################################################################################### */ /* main */ /* ################################################################################### */ int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); char *scoreSchemeName = NULL; optionHash(&argc, argv); struct twoBitFile *tbf; boolean didNetMyself = FALSE; /* flag. True if we did the netting */ -struct dyString* cmd = newDyString(500); /* for chainSort */ +struct dyString* cmd = dyStringNew(500); /* for chainSort */ int retVal = 0; char outChainFileUnsorted [500]; if (argc != 6) usage(); if (debug) printf("### DEBUG mode ###\n"); /* get all the options */ inChainFile = argv[1]; tNibDir = argv[2]; qNibDir = argv[3]; outChainFile = argv[4]; safef(outChainFileUnsorted, sizeof(outChainFileUnsorted), "%s.unsorted", outChainFile);