080a160c7b9595d516c9c70e83689a09b60839d0
galt
  Mon Jun 3 12:16:53 2013 -0700
fix SQL Injection
diff --git src/hg/lib/mafSummary.c src/hg/lib/mafSummary.c
index 1a9d12b..e7b5827 100644
--- src/hg/lib/mafSummary.c
+++ src/hg/lib/mafSummary.c
@@ -91,67 +91,39 @@
 while ((row = sqlNextRow(sr)) != NULL)
     {
     el = mafSummaryLoad(row);
     slAddHead(&list, el);
     }
 slReverse(&list);
 sqlFreeResult(&sr);
 return list;
 }
 
 void mafSummarySaveToDb(struct sqlConnection *conn, struct mafSummary *el, char *tableName, int updateSize)
 /* Save mafSummary 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 mafSummarySaveToDbEscaped() */
+ * 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',%u,%u,'%s',%g,'%s','%s')", 
+sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%g,'%s','%s')", 
 	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->src,  el->score,  el->leftStatus,  el->rightStatus);
 sqlUpdate(conn, update->string);
 freeDyString(&update);
 }
 
-void mafSummarySaveToDbEscaped(struct sqlConnection *conn, struct mafSummary *el, char *tableName, int updateSize)
-/* Save mafSummary 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 mafSummarySaveToDb().
- * For example automatically copies and converts: 
- * "autosql's features include" --> "autosql\'s features include" 
- * before inserting into database. */ 
-{
-struct dyString *update = newDyString(updateSize);
-char  *chrom, *src, *leftStatus, *rightStatus;
-chrom = sqlEscapeString(el->chrom);
-src = sqlEscapeString(el->src);
-leftStatus = sqlEscapeString(el->leftStatus);
-rightStatus = sqlEscapeString(el->rightStatus);
-
-dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%g,'%s','%s')", 
-	tableName,  chrom, el->chromStart , el->chromEnd ,  src, el->score ,  leftStatus,  rightStatus);
-sqlUpdate(conn, update->string);
-freeDyString(&update);
-freez(&chrom);
-freez(&src);
-freez(&leftStatus);
-freez(&rightStatus);
-}
-
 struct mafSummary *mafSummaryCommaIn(char **pS, struct mafSummary *ret)
 /* Create a mafSummary out of a comma separated string. 
  * This will fill in ret if non-null, otherwise will
  * return a new mafSummary */
 {
 char *s = *pS;
 
 if (ret == NULL)
     AllocVar(ret);
 ret->chrom = sqlStringComma(&s);
 ret->chromStart = sqlUnsignedComma(&s);
 ret->chromEnd = sqlUnsignedComma(&s);
 ret->src = sqlStringComma(&s);
 ret->score = sqlFloatComma(&s);
 sqlFixedStringComma(&s, ret->leftStatus, sizeof(ret->leftStatus));
@@ -221,31 +193,31 @@
 char *createString =
 "#Positions and scores for alignment blocks\n"
 "CREATE TABLE %s (\n"
 "       bin smallint unsigned not null,\n"
 "       chrom varchar(255) not null,	# Chromosome\n"
 "       chromStart int unsigned not null,	# Start position in chromosome\n"
 "       chromEnd int unsigned not null,	# End position in chromosome\n"
 "       src varchar(255) not null,	# Sequence name or database of alignment\n"
 "       score float not null,	# Floating point score (0.0 to 1.0).\n"
 "          #Indices\n"
 "       leftStatus char(1),     # Status WRT preceding block\n"
 "       rightStatus char(1),    # Status WRT following block\n"
 "    INDEX(chrom(%d),bin)\n"
 ")\n";
 struct dyString *dy = newDyString(1024);
-dyStringPrintf(dy, createString, tableName, indexSize, indexSize, indexSize);
+sqlDyStringPrintf(dy, createString, tableName, indexSize, indexSize, indexSize);
 sqlRemakeTable(conn, tableName, dy->string);
 dyStringFree(&dy);
 }
 
 struct mafSummary *mafSummaryMiniLoad(char **row)
 /* Load a mafSummary from row fetched with select * from mafSummary
  * from database, except dummy in the {left,right}Status fields.
  * For use on earlier version of mafSummary tables.
  * Dispose of this with mafSummaryFree(). */
 {
 struct mafSummary *ret;
 
 AllocVar(ret);
 ret->chrom = cloneString(row[0]);
 ret->chromStart = sqlUnsigned(row[1]);