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/oneShot/rcvs/rcvs.c src/hg/oneShot/rcvs/rcvs.c index d997a9c..95a5106 100644 --- src/hg/oneShot/rcvs/rcvs.c +++ src/hg/oneShot/rcvs/rcvs.c @@ -19,46 +19,48 @@ "options:\n" " -xxx=XXX\n" ); } void rcvs(char *codingTable, char *clusterTable) /* rcvs - Compare riken noncoding vs. nonspliced. */ { struct hash *idHash = newHash(16); // Key id1, val id2 struct hash *nonCodingHash = newHash(16); // Key clusterId, value struct hash *splicedHash = newHash(16); // Key id2, present if spliced struct sqlConnection *conn = sqlConnect("mgsc"); struct sqlResult *sr; char **row; char *words[16]; -int wordCount; struct lineFile *lf; int codingSpliced = 0; int noncodingSpliced = 0; int codingNonspliced = 0; int noncodingNonspliced = 0; /* Read id's into hash */ -sr = sqlGetResult(conn, NOSQLINJ "select id1,id2 from rikenIds"); +char query[1024]; +sqlSafef(query, sizeof query, "select id1,id2 from rikenIds"); +sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) hashAdd(idHash, row[0], cloneString(row[1])); sqlFreeResult(&sr); /* Read spliced into hash */ -sr = sqlGetResult(conn, - NOSQLINJ "select name from rikenOrientInfo where intronOrientation != 0"); +sqlSafef(query, sizeof query, + "select name from rikenOrientInfo where intronOrientation != 0"); +sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) hashAdd(splicedHash, row[0], NULL); sqlFreeResult(&sr); /* Read noncoding clusters into hash */ lf = lineFileOpen(codingTable, TRUE); while (lineFileNextRow(lf, words, 2)) { if (sameString(words[1], "NoPProt")) hashAdd(nonCodingHash, words[0], NULL); } lineFileClose(&lf); /* Stream through cluster table counting and correlating. */ lf = lineFileOpen(clusterTable, TRUE);