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/mousePoster/mousePoster.c src/hg/mouseStuff/mousePoster/mousePoster.c index 8cdf7bf..74bee28 100644 --- src/hg/mouseStuff/mousePoster/mousePoster.c +++ src/hg/mouseStuff/mousePoster/mousePoster.c @@ -198,31 +198,33 @@ } lineFileClose(&lf); printf("Found %d misplaced (%d resolved dupes) in %s\n", missCount, resolvedDupeCount, misplacedFile); } struct hash *makeLocusLinkToJaxHash(struct sqlConnection *conn) /* Make hash keyed by locus link ID with value * of Jackson Labs ID. */ { struct hash *hash = newHash(0); struct sqlResult *sr; char **row; int count = 0; -sr = sqlGetResult(conn, NOSQLINJ "select LLid, MGIid from MGIid"); +char query[1024]; +sqlSafef(query, sizeof query, "select LLid, MGIid from MGIid"); +sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *jaxId = cloneString(row[1]); hashAdd(hash, row[0], jaxId); ++count; } sqlFreeResult(&sr); return hash; } void fillFirstColumnHash(char *fileName, struct hash *hash) /* Fill in hash with ID's in first column of file. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); char *row[1]; @@ -296,31 +298,33 @@ * genes that have mouse clones, and genes where have both. * Note that these are actually from three separate sources * though theoretically you could calculate the intersection set. * Safer to use stuff straight from Jackson Labs though I think. * These hashes are all keyed by the RefSeq accession. */ { struct hash *morbidHash = parseMorbidMap(morbidMapFile); struct hash *llToJax = makeLocusLinkToJaxHash(conn); struct hash *jaxDiseaseHash = makeDiseaseOrthoHash(orthoFile, morbidHash); struct hash *jaxStockHash = makeFirstColumnHash(stockFile); struct hash *jaxDiseaseStockHash = makeFirstColumnHash(diseaseStockFile); struct sqlResult *sr; char **row; /* Using ensembl fillFirstColumnHash(diseaseFile, diseaseHash); */ -sr = sqlGetResult(conn, NOSQLINJ "select mrnaAcc,locusLinkId from refLink"); +char query[1024]; +sqlSafef(query, sizeof query, "select mrnaAcc,locusLinkId from refLink"); +sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *acc = row[0]; char *llId = row[1]; if (!sameString(llId,"0")) { char *jaxId = hashFindVal(llToJax, llId); if (jaxId != NULL) { if (hashLookup(jaxStockHash, jaxId)) { hashAdd(stockHash, acc, NULL); } if (hashLookup(jaxDiseaseStockHash, jaxId)) {