Skip to content

Commit 701c863

Browse files
committed
patch 9.1.0722: crash with large id in text_prop interface
Problem: crash with large id in text_prop interface prop_add()/prop_add_list() (cposture) Solution: Error out if the id is > INT_MAX or <= INT_MIN fixes: #15637 closes: #15638 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 5b9237c commit 701c863

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

runtime/doc/textprop.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*textprop.txt* For Vim version 9.1. Last change: 2024 Jun 08
1+
*textprop.txt* For Vim version 9.1. Last change: 2024 Sep 08
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -140,10 +140,10 @@ prop_add({lnum}, {col}, {props})
140140
bufnr buffer to add the property to; when omitted
141141
the current buffer is used
142142
id user defined ID for the property; must be a
143-
number, should be positive; when using "text"
144-
then "id" must not be present and will be set
145-
automatically to a negative number; otherwise
146-
zero is used
143+
number, should be positive |E1510|;
144+
when using "text" then "id" must not be
145+
present and will be set automatically to a
146+
negative number; otherwise zero is used
147147
*E1305*
148148
text text to be displayed before {col}, or
149149
above/below the line if {col} is zero; prepend
@@ -271,7 +271,7 @@ prop_add_list({props}, [{item}, ...]) *prop_add_list()*
271271
call prop_add_list(#{type: 'MyProp', id: 2},
272272
\ [[1, 4, 1, 7],
273273
\ [1, 15, 1, 20],
274-
\ [2, 30, 3, 30]]
274+
\ [2, 30, 3, 30]])
275275
<
276276
Can also be used as a |method|: >
277277
GetProp()->prop_add_list([[1, 1, 1, 2], [1, 4, 1, 8]])

src/testdir/test_textprop.vim

+4
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ func Test_prop_add_list()
393393
call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:')
394394
call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:')
395395
call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:')
396+
call assert_fails('call prop_add_list(#{type: "one", id: 2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:')
397+
call assert_fails('call prop_add_list(#{type: "one", id: -2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:')
396398

397399
" only one error for multiple wrong values
398400
call assert_fails('call prop_add_list(#{type: "one"}, [[{}, [], 0z00, 0.3]])', ['E728:', 'E728:'])
@@ -1780,6 +1782,8 @@ func Test_prop_func_invalid_args()
17801782
call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:')
17811783
call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:')
17821784
call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:')
1785+
call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': 2147483648})", 'E1510:')
1786+
call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': -2147483648})", 'E1510:')
17831787

17841788
call prop_type_delete('xxx')
17851789
bwipe!

src/textprop.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,16 @@ f_prop_add_list(typval_T *argvars, typval_T *rettv UNUSED)
372372
type_name = dict_get_string(dict, "type", FALSE);
373373

374374
if (dict_has_key(dict, "id"))
375-
id = dict_get_number(dict, "id");
375+
{
376+
vimlong_T x;
377+
x = dict_get_number(dict, "id");
378+
if (x > INT_MAX || x <= INT_MIN)
379+
{
380+
semsg(_(e_val_too_large), dict_get_string(dict, "id", FALSE));
381+
return;
382+
}
383+
id = (int)x;
384+
}
376385

377386
if (get_bufnr_from_arg(&argvars[0], &buf) == FAIL)
378387
return;
@@ -497,7 +506,16 @@ prop_add_common(
497506
end_col = 1;
498507

499508
if (dict_has_key(dict, "id"))
500-
id = dict_get_number(dict, "id");
509+
{
510+
vimlong_T x;
511+
x = dict_get_number(dict, "id");
512+
if (x > INT_MAX || x <= INT_MIN)
513+
{
514+
semsg(_(e_val_too_large), dict_get_string(dict, "id", FALSE));
515+
goto theend;
516+
}
517+
id = (int)x;
518+
}
501519

502520
if (dict_has_key(dict, "text"))
503521
{

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
722,
707709
/**/
708710
721,
709711
/**/

0 commit comments

Comments
 (0)