summaryrefslogtreecommitdiffstats
path: root/generic/tkTextMark.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-01-25 21:13:39 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-01-25 21:13:39 (GMT)
commitf309ff804398b57a180a79ebaaa297a8343a1c84 (patch)
treeeecb0149dc58d041678d5df28192820f1ff55ae1 /generic/tkTextMark.c
parent46763e67f1830a5bb94b2576b9029f0b21aa789f (diff)
parent4a92b56b21aedd59eba10bfe67c863da54968786 (diff)
downloadtk-f309ff804398b57a180a79ebaaa297a8343a1c84.zip
tk-f309ff804398b57a180a79ebaaa297a8343a1c84.tar.gz
tk-f309ff804398b57a180a79ebaaa297a8343a1c84.tar.bz2
[Bug-1630271]: segfault/infinite loop when a mark is before -startline
Diffstat (limited to 'generic/tkTextMark.c')
-rw-r--r--generic/tkTextMark.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c
index 55edb46..0e51e33 100644
--- a/generic/tkTextMark.c
+++ b/generic/tkTextMark.c
@@ -402,6 +402,8 @@ TkTextMarkNameToIndex(
TkTextIndex *indexPtr) /* Index information gets stored here. */
{
TkTextSegment *segPtr;
+ TkTextIndex index;
+ int start, end;
if (textPtr == NULL) {
return TCL_ERROR;
@@ -420,6 +422,29 @@ TkTextMarkNameToIndex(
segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
}
TkTextMarkSegToIndex(textPtr, segPtr, indexPtr);
+
+ /* If indexPtr refers to somewhere outside the -startline/-endline
+ * range limits of the widget, error out since the mark indeed is not
+ * reachable from this text widget (it may be reachable from a peer)
+ * (bug 1630271).
+ */
+
+ if (textPtr->start != NULL) {
+ start = TkBTreeLinesTo(NULL, textPtr->start);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
+ &index);
+ if (TkTextIndexCmp(indexPtr, &index) < 0) {
+ return TCL_ERROR;
+ }
+ }
+ if (textPtr->end != NULL) {
+ end = TkBTreeLinesTo(NULL, textPtr->end);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, end, 0,
+ &index);
+ if (TkTextIndexCmp(indexPtr, &index) > 0) {
+ return TCL_ERROR;
+ }
+ }
return TCL_OK;
}