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/hgJaxQtl/hgJaxQtl.c src/hg/makeDb/outside/hgJaxQtl/hgJaxQtl.c index acdadb1..0c307e8 100644 --- src/hg/makeDb/outside/hgJaxQtl/hgJaxQtl.c +++ src/hg/makeDb/outside/hgJaxQtl/hgJaxQtl.c @@ -12,43 +12,43 @@ errAbort( "hgJaxQtl - generate bed file for jaxQTL3 table \n" " using the table jaxQtlRaw as input\n" " output file is jaxQTL3.tab.\n" "usage:\n" " hgJaxQtl xxxx\n" " xxxx is the database\n" "example: hgJaxQtl mm5\n"); } /* get valid identNo from stsMapMouseNew table, return NULL if not found */ char *getStsId(struct sqlConnection *conn3, char *database, char *stsName) { char cond_str[255]; char *identNo; -sqlSafefFrag(cond_str, sizeof(cond_str), "name='%s'", stsName); +sqlSafef(cond_str, sizeof(cond_str), "name='%s'", stsName); identNo = sqlGetField(database, "stsMapMouseNew", "identNo", cond_str); if (identNo == NULL) { /* check to see if stsAlias has it */ - sqlSafefFrag(cond_str, sizeof(cond_str), "alias='%s'", stsName); + sqlSafef(cond_str, sizeof(cond_str), "alias='%s'", stsName); identNo = sqlGetField(database, "stsAlias", "identNo", cond_str); /* now make sure that stsMapMouseNew has an entry for this identNo */ if (identNo != NULL) { - sqlSafefFrag(cond_str, sizeof(cond_str), "identNo=%s", identNo); + sqlSafef(cond_str, sizeof(cond_str), "identNo=%s", identNo); identNo = sqlGetField(database, "stsMapMouseNew", "identNo", cond_str); } } return(identNo); } int main(int argc, char *argv[]) { struct sqlConnection *conn2, *conn3; char query2[256], query3[256]; struct sqlResult *sr2, *sr3; char **row2, **row3; FILE *outF;