080a160c7b9595d516c9c70e83689a09b60839d0 galt Mon Jun 3 12:16:53 2013 -0700 fix SQL Injection diff --git src/hg/lib/taxonDivision.c src/hg/lib/taxonDivision.c index 63ad157..4fb4069 100644 --- src/hg/lib/taxonDivision.c +++ src/hg/lib/taxonDivision.c @@ -85,64 +85,39 @@ while ((row = sqlNextRow(sr)) != NULL) { el = taxonDivisionLoad(row); slAddHead(&list, el); } slReverse(&list); sqlFreeResult(&sr); return list; } void taxonDivisionSaveToDb(struct sqlConnection *conn, struct taxonDivision *el, char *tableName, int updateSize) /* Save taxonDivision 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 taxonDivisionSaveToDbEscaped() */ + * inserted as NULL. Strings are automatically escaped to allow insertion into the database. */ { struct dyString *update = newDyString(updateSize); -dyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s')", +sqlDyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s')", tableName, el->id, el->code, el->name, el->comments); sqlUpdate(conn, update->string); freeDyString(&update); } -void taxonDivisionSaveToDbEscaped(struct sqlConnection *conn, struct taxonDivision *el, char *tableName, int updateSize) -/* Save taxonDivision 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 taxonDivisionSaveToDb(). - * For example automatically copies and converts: - * "autosql's features include" --> "autosql\'s features include" - * before inserting into database. */ -{ -struct dyString *update = newDyString(updateSize); -char *code, *name, *comments; -code = sqlEscapeString(el->code); -name = sqlEscapeString(el->name); -comments = sqlEscapeString(el->comments); - -dyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s')", - tableName, el->id , code, name, comments); -sqlUpdate(conn, update->string); -freeDyString(&update); -freez(&code); -freez(&name); -freez(&comments); -} struct taxonDivision *taxonDivisionCommaIn(char **pS, struct taxonDivision *ret) /* Create a taxonDivision out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new taxonDivision */ { char *s = *pS; if (ret == NULL) AllocVar(ret); ret->id = sqlUnsignedComma(&s); sqlFixedStringComma(&s, ret->code, sizeof(ret->code)); ret->name = sqlStringComma(&s); ret->comments = sqlStringComma(&s); *pS = s;