080a160c7b9595d516c9c70e83689a09b60839d0
galt
Mon Jun 3 12:16:53 2013 -0700
fix SQL Injection
diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c
index 09d4642..c4fd801 100644
--- src/hg/hgc/pubs.c
+++ src/hg/hgc/pubs.c
@@ -211,31 +211,31 @@
long size = end - start;
sprintLongWithCommas(startBuf, size);
if (showSize)
printf("Genomic Size: %s
\n", startBuf);
}
static void printFilterLink(char *pslTrack, char *articleId, char *articleTable)
/* print a link to hgTracks with an additional cgi param to activate the single article filter */
{
int start = cgiOptionalInt("o", -1);
if (start==-1)
return;
int end = cgiInt("t");
char qBuf[1024];
struct sqlConnection *conn = hAllocConn(database);
- safef(qBuf, sizeof(qBuf), "SELECT CONCAT(firstAuthor, year) FROM %s WHERE articleId='%s';", articleTable, articleId);
+ sqlSafef(qBuf, sizeof(qBuf), "SELECT CONCAT(firstAuthor, year) FROM %s WHERE articleId='%s';", articleTable, articleId);
char *dispId = sqlQuickString(conn, qBuf);
printf(
"
", hgTracksPathAndSettings(), database, seqName, start+1, end, articleId, pslTrack, dispId); printf("Show these sequence matches individually on genome browser (activates track \"" "Individual matches for article\")
"); printPositionAndSize(start, end, 1); printf( "\n");
}
static void printLimitWarning(struct sqlConnection *conn, char *markerTable,
char *item, int itemLimit, char *sectionList)
{
char query[4000];
-safef(query, sizeof(query), "SELECT COUNT(*) from %s WHERE markerId='%s' AND section in (%s) ", markerTable, item, sectionList);
+sqlSafef(query, sizeof(query), "SELECT COUNT(*) from %s WHERE markerId='%s' AND section in (%s) ", markerTable, item, sectionList);
if (sqlNeedQuickNum(conn, query) > itemLimit)
{
printf("This marker is mentioned more than %d times
\n", itemLimit);
printf("The results would take too long to load in your browser and are "
"therefore limited to %d articles.
\n", itemLimit); } } static void printMarkerSnippets(struct sqlConnection *conn, char *articleTable, char *markerTable, char *item) { /* do not show more snippets than this limit */ int itemLimit=100; printSectionCheckboxes(); @@ -391,31 +391,31 @@ freeMem(sectionList); sqlFreeResult(&sr); } static char *urlToLogoUrl(char *pubsArticleTable, char *articleId, char *urlOrig) /* return a string with relative path of logo for publisher given the url of * fulltext or a table/articleId, has to be freed */ { struct sqlConnection *conn = hAllocConn(database); char *pubCode = NULL; if (hHasField("hgFixed", pubsArticleTable, "publisher")) { char query[4000]; - safef(query, sizeof(query), "SELECT publisher from %s where articleId=%s", + sqlSafef(query, sizeof(query), "SELECT publisher from %s where articleId=%s", pubsArticleTable, articleId); pubCode = sqlQuickString(conn, query); } else { // get top-level domain url if not publisher field char url[1024]; memcpy(url, urlOrig, sizeof(url)); char *slashParts[20]; // split http://www.sgi.com/test -> to [http:,www.sgi.com,test] int partCount = chopString(url, "/", slashParts, ArraySize(slashParts)); if (partCount<3) return NULL; // split www.sgi.com to [www,sgi,com] char *dotParts[20]; @@ -424,31 +424,31 @@ return NULL; pubCode = dotParts[partCount-2]; } // construct path to image char *logoUrl = needMem(512); safef(logoUrl, 512, "../images/pubs_%s.png", pubCode); return logoUrl; } static char *printArticleInfo(struct sqlConnection *conn, char *item, char *pubsArticleTable) /* Header with information about paper, return documentId */ { char query[512]; -safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid, " +sqlSafef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid, " "source, extId FROM %s WHERE articleId='%s'", pubsArticleTable, item); struct sqlResult *sr = sqlGetResult(conn, query); char **row; char *articleId=NULL; if ((row = sqlNextRow(sr)) == NULL) { printf("Could not resolve articleId %s, this is an internal error.\n", item); printf("Please send an email to max@soe.ucsc.edu\n"); sqlFreeResult(&sr); return NULL; } articleId = cloneString(row[0]); char *url = row[1]; @@ -496,38 +496,38 @@ if (pubsIsElsevier) printf("
Copyright 2012 Elsevier B.V. All rights reserved.
"); sqlFreeResult(&sr); return articleId; } static struct hash *getSeqIdHash(struct sqlConnection *conn, char *trackTable, \ char *articleId, char *item, char *seqName, int start) /* return a hash with the sequence IDs for a given chain of BLAT matches */ { if (start==-1) return NULL; char query[512]; /* check first if the column exists (some debugging tables on hgwdev don't have seqIds) */ -safef(query, sizeof(query), "SHOW COLUMNS FROM %s LIKE 'seqIds';", trackTable); +sqlSafef(query, sizeof(query), "SHOW COLUMNS FROM %s LIKE 'seqIds';", trackTable); char *seqIdPresent = sqlQuickString(conn, query); if (!seqIdPresent) { return NULL; } /* get sequence-Ids for feature that was clicked (item&startPos are unique) and return as hash*/ -safef(query, sizeof(query), "SELECT seqIds,'' FROM %s WHERE name='%s' " +sqlSafef(query, sizeof(query), "SELECT seqIds,'' FROM %s WHERE name='%s' " "and chrom='%s' and chromStart=%d;", trackTable, item, seqName, start); if (pubsDebug) printf("%s