From 3bb9addd4d1a898eb17a9959f6aaaf56b81cf95b Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 13 Mar 2015 13:50:25 +1100 Subject: Truncate elements that are near to maxItemLen to avoid possibility of writing outside bounds. Also avoids warning for use of strncpy. --- src/AutoComplete.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/AutoComplete.cxx') diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index d154a913a..27eed53b9 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -167,7 +167,9 @@ void AutoComplete::SetList(const char *list) { char item[maxItemLen]; for (size_t i = 0; i < sortMatrix.size(); ++i) { int wordLen = IndexSort.indices[sortMatrix[i] * 2 + 2] - IndexSort.indices[sortMatrix[i] * 2]; - strncpy(item, list + IndexSort.indices[sortMatrix[i] * 2], wordLen); + if (wordLen > maxItemLen-2) + wordLen = maxItemLen - 2; + memcpy(item, list + IndexSort.indices[sortMatrix[i] * 2], wordLen); if ((i+1) == sortMatrix.size()) { // Last item so remove separator if present if ((wordLen > 0) && (item[wordLen-1] == separator)) -- cgit v1.2.3