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/intronEnds/intronEnds.c src/hg/intronEnds/intronEnds.c index 3616793..0fc57e6 100644 --- src/hg/intronEnds/intronEnds.c +++ src/hg/intronEnds/intronEnds.c @@ -20,54 +20,54 @@ /* Explain usage and exit. */ { errAbort( "intronEnds - Gather stats on intron ends.\n" "usage:\n" " intronEnds database geneTable\n" "options:\n" " -chrom=chrN - restrict to a particular chromosome\n" " -withUtr - restrict to genes with UTR regions\n" ); } void intronEnds(char *database, char *table) /* intronEnds - Gather stats on intron ends.. */ { -struct dyString *query = newDyString(1024); +struct dyString *query = dyStringNew(1024); struct sqlConnection *conn; struct sqlResult *sr; char **row; struct genePred *gp; int total = 0; int gtag = 0; int gcag = 0; int atac = 0; int ctac = 0; DNA ends[4]; int exonIx, txStart; struct dnaSeq *seq; int rowOffset; char strand; rowOffset = hOffsetPastBin(database, 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); strand = gp->strand[0]; txStart = gp->txStart; seq = hDnaFromSeq(database, gp->chrom, txStart, gp->txEnd, dnaLower); for (exonIx=1; exonIx < gp->exonCount; ++exonIx) { ++total; memcpy(ends, seq->dna + gp->exonEnds[exonIx-1] - txStart, 2); memcpy(ends+2, seq->dna + gp->exonStarts[exonIx] - txStart - 2, 2); if (strand == '-')