080a160c7b9595d516c9c70e83689a09b60839d0
galt
  Mon Jun 3 12:16:53 2013 -0700
fix SQL Injection
diff --git src/hg/lib/gencodeIntron.c src/hg/lib/gencodeIntron.c
index 6963c2f..2e98e9c 100644
--- src/hg/lib/gencodeIntron.c
+++ src/hg/lib/gencodeIntron.c
@@ -93,70 +93,39 @@
 while ((row = sqlNextRow(sr)) != NULL)
     {
     el = gencodeIntronLoad(row+rowOffset);
     slAddHead(&list, el);
     }
 slReverse(&list);
 sqlFreeResult(&sr);
 return list;
 }
 
 void gencodeIntronSaveToDb(struct sqlConnection *conn, struct gencodeIntron *el, char *tableName, int updateSize)
 /* Save gencodeIntron 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 gencodeIntronSaveToDbEscaped() */
+ * 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','%s','%s','%s','%s')", 
+sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s','%s','%s','%s','%s')", 
 	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->status,  el->strand,  el->transcript,  el->geneId);
 sqlUpdate(conn, update->string);
 freeDyString(&update);
 }
 
-void gencodeIntronSaveToDbEscaped(struct sqlConnection *conn, struct gencodeIntron *el, char *tableName, int updateSize)
-/* Save gencodeIntron 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 gencodeIntronSaveToDb().
- * 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, *name, *status, *strand, *transcript, *geneId;
-chrom = sqlEscapeString(el->chrom);
-name = sqlEscapeString(el->name);
-status = sqlEscapeString(el->status);
-strand = sqlEscapeString(el->strand);
-transcript = sqlEscapeString(el->transcript);
-geneId = sqlEscapeString(el->geneId);
-
-dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s','%s','%s','%s','%s')", 
-	tableName,  chrom, el->chromStart , el->chromEnd ,  name,  status,  strand,  transcript,  geneId);
-sqlUpdate(conn, update->string);
-freeDyString(&update);
-freez(&chrom);
-freez(&name);
-freez(&status);
-freez(&strand);
-freez(&transcript);
-freez(&geneId);
-}
 
 struct gencodeIntron *gencodeIntronCommaIn(char **pS, struct gencodeIntron *ret)
 /* Create a gencodeIntron out of a comma separated string. 
  * This will fill in ret if non-null, otherwise will
  * return a new gencodeIntron */
 {
 char *s = *pS;
 
 if (ret == NULL)
     AllocVar(ret);
 ret->chrom = sqlStringComma(&s);
 ret->chromStart = sqlUnsignedComma(&s);
 ret->chromEnd = sqlUnsignedComma(&s);
 ret->name = sqlStringComma(&s);
 ret->status = sqlStringComma(&s);
@@ -235,20 +204,20 @@
 {
 char *createString =
 "CREATE TABLE %s (\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"
 "       name varchar(255) not null,	# Intron ID\n"
 "       status enum('not_tested', 'RT_positive','RT_negative','RT_wrong_junction','RT_submitted', 'RACE_validated'),      # Status\n"
 "       strand char(1) not null,	# + or -\n"
 "       transcript varchar(255) not null,	# Transcript ID from GTF\n"
 "       geneId varchar(255) not null,	# Gene ID from GTF\n"
 "    INDEX(chrom(%d),chromStart),\n"
 "    INDEX(chrom(%d),chromEnd)\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);
 }