080a160c7b9595d516c9c70e83689a09b60839d0 galt Mon Jun 3 12:16:53 2013 -0700 fix SQL Injection diff --git src/hg/lib/affy10KDetails.c src/hg/lib/affy10KDetails.c index cd9ba4e..74c0aa1 100644 --- src/hg/lib/affy10KDetails.c +++ src/hg/lib/affy10KDetails.c @@ -92,75 +92,39 @@ while ((row = sqlNextRow(sr)) != NULL) { el = affy10KDetailsLoad(row); slAddHead(&list, el); } slReverse(&list); sqlFreeResult(&sr); return list; } void affy10KDetailsSaveToDb(struct sqlConnection *conn, struct affy10KDetails *el, char *tableName, int updateSize) /* Save affy10KDetails as a row to the table specified by tableName. * As blob fields may be arbitrary size updateSize specifies the approx size * of a string that would contain the entire query. Arrays of native types are * converted to comma separated strings and loaded as such, User defined types are - * inserted as NULL. Note that strings must be escaped to allow insertion into the database. - * For example "autosql's features include" --> "autosql\'s features include" - * If worried about this use affy10KDetailsSaveToDbEscaped() */ + * inserted as NULL. Strings are automatically escaped to allow insertion into the database. */ { struct dyString *update = newDyString(updateSize); -dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s')", +sqlDyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s')", tableName, el->affyId, el->rsId, el->tscId, el->baseA, el->baseB, el->sequenceA, el->sequenceB, el->enzyme); sqlUpdate(conn, update->string); freeDyString(&update); } -void affy10KDetailsSaveToDbEscaped(struct sqlConnection *conn, struct affy10KDetails *el, char *tableName, int updateSize) -/* Save affy10KDetails as a row to the table specified by tableName. - * As blob fields may be arbitrary size updateSize specifies the approx size. - * of a string that would contain the entire query. Automatically - * escapes all simple strings (not arrays of string) but may be slower than affy10KDetailsSaveToDb(). - * For example automatically copies and converts: - * "autosql's features include" --> "autosql\'s features include" - * before inserting into database. */ -{ -struct dyString *update = newDyString(updateSize); -char *affyId, *rsId, *tscId, *baseA, *baseB, *sequenceA, *sequenceB, *enzyme; -affyId = sqlEscapeString(el->affyId); -rsId = sqlEscapeString(el->rsId); -tscId = sqlEscapeString(el->tscId); -baseA = sqlEscapeString(el->baseA); -baseB = sqlEscapeString(el->baseB); -sequenceA = sqlEscapeString(el->sequenceA); -sequenceB = sqlEscapeString(el->sequenceB); -enzyme = sqlEscapeString(el->enzyme); - -dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s')", - tableName, affyId, rsId, tscId, baseA, baseB, sequenceA, sequenceB, enzyme); -sqlUpdate(conn, update->string); -freeDyString(&update); -freez(&affyId); -freez(&rsId); -freez(&tscId); -freez(&baseA); -freez(&baseB); -freez(&sequenceA); -freez(&sequenceB); -freez(&enzyme); -} - struct affy10KDetails *affy10KDetailsCommaIn(char **pS, struct affy10KDetails *ret) /* Create a affy10KDetails out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new affy10KDetails */ { char *s = *pS; if (ret == NULL) AllocVar(ret); ret->affyId = sqlStringComma(&s); ret->rsId = sqlStringComma(&s); ret->tscId = sqlStringComma(&s); sqlFixedStringComma(&s, ret->baseA, sizeof(ret->baseA)); sqlFixedStringComma(&s, ret->baseB, sizeof(ret->baseB)); sqlFixedStringComma(&s, ret->sequenceA, sizeof(ret->sequenceA));