mirror of
https://github.com/neovim/neovim.git
synced 2026-02-19 01:48:30 +00:00
vim-patch:9.1.1954: Setting a byte in a blob, accepts values outside 0-255
Problem: Setting a byte in a blob, accepts values outside 0-255
Solution: When setting a byte in a blob, check for valid values
(Yegappan Lakshmanan)
closes: vim/vim#18870
f4a299700e
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -197,6 +197,7 @@ EXTERN const char e_invalid_line_number_nr[] INIT(= N_("E966: Invalid line numbe
|
||||
|
||||
EXTERN const char e_reduce_of_an_empty_str_with_no_initial_value[] INIT(= N_("E998: Reduce of an empty %s with no initial value"));
|
||||
|
||||
EXTERN const char e_invalid_value_for_blob_nr[] INIT(= N_("E1239: Invalid value for blob: 0x" PRIX64));
|
||||
EXTERN const char e_stray_closing_curly_str[]
|
||||
INIT(= N_("E1278: Stray '}' without a matching '{': %s"));
|
||||
EXTERN const char e_missing_close_curly_str[]
|
||||
|
||||
@@ -1315,9 +1315,13 @@ void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, bool copy, const bool
|
||||
}
|
||||
} else {
|
||||
bool error = false;
|
||||
const char val = (char)tv_get_number_chk(rettv, &error);
|
||||
const varnumber_T val = tv_get_number_chk(rettv, &error);
|
||||
if (!error) {
|
||||
tv_blob_set_append(lp->ll_blob, lp->ll_n1, (uint8_t)val);
|
||||
if (val < 0 || val > 255) {
|
||||
semsg(_(e_invalid_value_for_blob_nr), val);
|
||||
} else {
|
||||
tv_blob_set_append(lp->ll_blob, lp->ll_n1, (uint8_t)val);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (op != NULL && *op != '=') {
|
||||
|
||||
@@ -99,8 +99,6 @@ static const char e_list_or_blob_required_for_argument_nr[]
|
||||
= N_("E1226: List or Blob required for argument %d");
|
||||
static const char e_blob_required_for_argument_nr[]
|
||||
= N_("E1238: Blob required for argument %d");
|
||||
static const char e_invalid_value_for_blob_nr[]
|
||||
= N_("E1239: Invalid value for blob: %d");
|
||||
static const char e_string_list_or_blob_required_for_argument_nr[]
|
||||
= N_("E1252: String, List or Blob required for argument %d");
|
||||
static const char e_string_or_function_required_for_argument_nr[]
|
||||
|
||||
@@ -895,4 +895,13 @@ func Test_blob_items()
|
||||
call CheckSourceLegacyAndVim9Success(lines)
|
||||
endfunc
|
||||
|
||||
" Test for setting a byte in a blob with invalid value
|
||||
func Test_blob_byte_set_invalid_value()
|
||||
let lines =<< trim END
|
||||
VAR b = 0zD0C3E4E18E1B
|
||||
LET b[0] = 229539777187355
|
||||
END
|
||||
call CheckSourceLegacyAndVim9Failure(lines, 'E1239: Invalid value for blob:')
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
Reference in New Issue
Block a user