summaryrefslogtreecommitdiffstats
path: root/generic/tkTextBTree.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2011-03-28 09:20:54 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2011-03-28 09:20:54 (GMT)
commit2ddbd4ef22b8a849feab79bef67301fa85f2c5ea (patch)
tree24fac5f15845fd43092b4742e401d03fca969508 /generic/tkTextBTree.c
parent1c27734166504eba34c85ec8a991874ca4cd224f (diff)
parent74320cd3d0975d9d84a7693f2cdd08a84c20d165 (diff)
downloadtk-2ddbd4ef22b8a849feab79bef67301fa85f2c5ea.zip
tk-2ddbd4ef22b8a849feab79bef67301fa85f2c5ea.tar.gz
tk-2ddbd4ef22b8a849feab79bef67301fa85f2c5ea.tar.bz2
[Bug 3129527]: Fix buffer overflow w/ GCC 4.5 and -D_FORTIFY_SOURCE=2. One more place where this problem could appear.
Diffstat (limited to 'generic/tkTextBTree.c')
-rw-r--r--generic/tkTextBTree.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index b714546..e464cc6 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -1076,7 +1076,7 @@ TkBTreeInsertChars(
curPtr->nextPtr = segPtr;
}
segPtr->size = chunkSize;
- strncpy(segPtr->body.chars, string, (size_t) chunkSize);
+ memcpy(segPtr->body.chars, string, (size_t) chunkSize);
segPtr->body.chars[chunkSize] = 0;
if (eol[-1] != '\n') {
@@ -4550,12 +4550,13 @@ CharSplitProc(
newPtr1->typePtr = &tkTextCharType;
newPtr1->nextPtr = newPtr2;
newPtr1->size = index;
- strncpy(newPtr1->body.chars, segPtr->body.chars, (size_t) index);
+ memcpy(newPtr1->body.chars, segPtr->body.chars, (size_t) index);
newPtr1->body.chars[index] = 0;
newPtr2->typePtr = &tkTextCharType;
newPtr2->nextPtr = segPtr->nextPtr;
newPtr2->size = segPtr->size - index;
- strcpy(newPtr2->body.chars, segPtr->body.chars + index);
+ memcpy(newPtr2->body.chars, segPtr->body.chars + index, newPtr2->size);
+ newPtr2->body.chars[newPtr2->size] = 0;
ckfree((char *) segPtr);
return newPtr1;
}
@@ -4596,8 +4597,9 @@ CharCleanupProc(
newPtr->typePtr = &tkTextCharType;
newPtr->nextPtr = segPtr2->nextPtr;
newPtr->size = segPtr->size + segPtr2->size;
- strcpy(newPtr->body.chars, segPtr->body.chars);
- strcpy(newPtr->body.chars + segPtr->size, segPtr2->body.chars);
+ memcpy(newPtr->body.chars, segPtr->body.chars, segPtr->size);
+ memcpy(newPtr->body.chars + segPtr->size, segPtr2->body.chars, segPtr2->size);
+ newPtr->body.chars[newPtr->size] = 0;
ckfree((char *) segPtr);
ckfree((char *) segPtr2);
return newPtr;