summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDon Anderson <dda@ddanderson.com>2015-05-20 22:40:43 -0400
committerDon Anderson <dda@ddanderson.com>2015-05-20 22:40:43 -0400
commitc730ba868a8f307d152c49d436ce3161bf61336e (patch)
tree01c57be892983840d70d21836e30f370c657b156 /ext
parent2e1dac4cbbc949eba08870b0374df1b245fe4028 (diff)
downloadmongo-c730ba868a8f307d152c49d436ce3161bf61336e.tar.gz
WT-1940. Modify CSV extractor to copy the result string safely.
Diffstat (limited to 'ext')
-rw-r--r--ext/extractors/csv/csv_extractor.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/ext/extractors/csv/csv_extractor.c b/ext/extractors/csv/csv_extractor.c
index efab4ad2eba..1eb029d0ab3 100644
--- a/ext/extractors/csv/csv_extractor.c
+++ b/ext/extractors/csv/csv_extractor.c
@@ -60,9 +60,10 @@ static int
csv_extract(WT_EXTRACTOR *extractor, WT_SESSION *session,
const WT_ITEM *key, const WT_ITEM *value, WT_CURSOR *result_cursor)
{
- char ch, *p, *pend, *valstr;
+ char *copy, *p, *pend, *valstr;
const CSV_EXTRACTOR *cvs_extractor;
int i, ret;
+ size_t len;
(void)key; /* Unused parameters */
@@ -84,15 +85,17 @@ csv_extract(WT_EXTRACTOR *extractor, WT_SESSION *session,
pend = p + strlen(p);
/*
* The key we must return is a null terminated string, but p
- * is not NULL-terminated. Make it so, for the duration of
- * the insert operation. This is ugly. There are
- * alternatives, but they aren't pretty either.
+ * is not necessarily NULL-terminated. So make a copy, just
+ * for the duration of the insert.
*/
- ch = *pend;
- *pend = '\0';
- result_cursor->set_key(result_cursor, p);
+ len = pend - p;
+ if ((copy = malloc(len + 1)) == NULL)
+ return (errno);
+ strncpy(copy, p, len);
+ copy[len] = '\0';
+ result_cursor->set_key(result_cursor, copy);
ret = result_cursor->insert(result_cursor);
- *pend = ch;
+ free(copy);
if (ret != 0)
return (ret);
}