080a160c7b9595d516c9c70e83689a09b60839d0 galt Mon Jun 3 12:16:53 2013 -0700 fix SQL Injection diff --git src/hg/hgGeneRing/interaction.c src/hg/hgGeneRing/interaction.c index 0a760e0..b03b053 100644 --- src/hg/hgGeneRing/interaction.c +++ src/hg/hgGeneRing/interaction.c @@ -83,62 +83,39 @@ while ((row = sqlNextRow(sr)) != NULL) { el = interactionLoad(row); slAddHead(&list, el); } slReverse(&list); sqlFreeResult(&sr); return list; } void interactionSaveToDb(struct sqlConnection *conn, struct interaction *el, char *tableName, int updateSize) /* Save interaction 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 interactionSaveToDbEscaped() */ + * 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',%g)", +sqlDyStringPrintf(update, "insert into %s values ( '%s','%s',%g)", tableName, el->fromX, el->toY, el->score); sqlUpdate(conn, update->string); freeDyString(&update); } -void interactionSaveToDbEscaped(struct sqlConnection *conn, struct interaction *el, char *tableName, int updateSize) -/* Save interaction 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 interactionSaveToDb(). - * For example automatically copies and converts: - * "autosql's features include" --> "autosql\'s features include" - * before inserting into database. */ -{ -struct dyString *update = newDyString(updateSize); -char *fromX, *toY; -fromX = sqlEscapeString(el->fromX); -toY = sqlEscapeString(el->toY); - -dyStringPrintf(update, "insert into %s values ( '%s','%s',%g)", - tableName, fromX, toY, el->score ); -sqlUpdate(conn, update->string); -freeDyString(&update); -freez(&fromX); -freez(&toY); -} struct interaction *interactionCommaIn(char **pS, struct interaction *ret) /* Create a interaction out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new interaction */ { char *s = *pS; if (ret == NULL) AllocVar(ret); ret->fromX = sqlStringComma(&s); ret->toY = sqlStringComma(&s); ret->score = sqlFloatComma(&s); *pS = s; return ret;