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/makeDb/outside/hgBioCyc/hgBioCyc.c src/hg/makeDb/outside/hgBioCyc/hgBioCyc.c index 08c040e..f57fa5d 100644 --- src/hg/makeDb/outside/hgBioCyc/hgBioCyc.c +++ src/hg/makeDb/outside/hgBioCyc/hgBioCyc.c @@ -1,94 +1,94 @@ /* hgBioCyc - Creates bioCycPathway.tab for Known Genes to link to SRI BioCyc pathways */ /* 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 "hCommon.h" #include "hdb.h" FILE *inf; char line_in[10000]; char line[10000]; char *infileName; int aaLen; int cdsLen; char cond_str[256]; char *aaStr; void usage() /* Explain usage and exit. */ { errAbort( "bioCyc - Creates bioCycPathway.tab for Known Genes to link to SRI BioCyc pathways\n" "usage:\n" " hgBoCyc xxxx yyyy\n" " xxxx is the input file name\n" " yyyy is the genome under construction\n" "example:\n" " hgBioCyc gene-pathway.dat hg16\n"); } int main(int argc, char *argv[]) { FILE *o1; char *chp; char *genomeDBname; char refseqID[40], mapID[40]; char *kgID, *geneSymbol; if (argc != 3) usage(); infileName = argv[1]; genomeDBname = argv[2]; o1 = fopen("j.dat", "w"); inf = mustOpen(infileName, "r"); while (fgets(line_in, 1000, inf) != NULL) { strcpy(line, line_in); chp = strstr(line, "\t"); *chp = '\0'; strcpy(refseqID, line); again: chp ++; chp = strtok(chp, "\r\t\n"); if (chp == NULL) continue; - sqlSafefFrag(cond_str, sizeof cond_str, "alias='%s'", refseqID); + sqlSafef(cond_str, sizeof cond_str, "alias='%s'", refseqID); kgID=sqlGetField(genomeDBname, "kgAlias", "kgID", cond_str); // check with refLink if not found in kgAlias if (kgID == NULL) { - sqlSafefFrag(cond_str, sizeof cond_str, "mrnaAcc='%s'", refseqID); + sqlSafef(cond_str, sizeof cond_str, "mrnaAcc='%s'", refseqID); geneSymbol=sqlGetField(genomeDBname, "refLink", "name", cond_str); - sqlSafefFrag(cond_str, sizeof cond_str, "alias='%s'", geneSymbol); + sqlSafef(cond_str, sizeof cond_str, "alias='%s'", geneSymbol); kgID=sqlGetField(genomeDBname, "kgAlias", "kgID", cond_str); } strcpy(mapID, chp); if (kgID != NULL) { fprintf(o1, "%s\t%s\t%s\n", kgID, refseqID, mapID);fflush(stdout); } else { printf("%s not found in kgAlias nor in refLink\n", refseqID); } chp = chp + strlen(mapID); // process remaing refeqID(s) goto again; } fclose(o1); mustSystem("cat j.dat|sort|uniq >bioCycPathway.tab"); mustSystem("rm j.dat"); return 0; }