mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: Allow blacklist functions that shouldn't be accesible from eval
Blacklist deprecated functions and functions depending on channel_id
This commit is contained in:
parent
7e2348f2b1
commit
e536abc1e1
@ -37,6 +37,7 @@ c_proto = Ct(
|
||||
Cg(Cc(false), 'async') *
|
||||
(fill * Cg((P('FUNC_API_ASYNC') * Cc(true)), 'async') ^ -1) *
|
||||
(fill * Cg((P('FUNC_API_NOEXPORT') * Cc(true)), 'noexport') ^ -1) *
|
||||
(fill * Cg((P('FUNC_API_NOEVAL') * Cc(true)), 'noeval') ^ -1) *
|
||||
fill * P(';')
|
||||
)
|
||||
grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1)
|
||||
|
@ -25,12 +25,14 @@ local gperfpipe = io.open(funcsfname .. '.gperf', 'wb')
|
||||
local funcs = require('eval').funcs
|
||||
local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all"))
|
||||
for i,fun in ipairs(metadata) do
|
||||
if not fun.noeval then
|
||||
funcs['api_'..fun.name] = {
|
||||
args=#fun.parameters,
|
||||
func='api_wrapper',
|
||||
data='&handle_'..fun.name,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local funcsdata = io.open(funcs_file, 'w')
|
||||
funcsdata:write(mpack.pack(funcs))
|
||||
|
@ -56,6 +56,7 @@ Integer buffer_line_count(Buffer buffer, Error *err)
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return The line string
|
||||
String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
String rv = { .size = 0 };
|
||||
|
||||
@ -84,6 +85,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
||||
/// @param line The new line.
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
Object l = STRING_OBJ(line);
|
||||
Array array = { .items = &l, .size = 1 };
|
||||
@ -102,6 +104,7 @@ void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
|
||||
/// @param index The line index
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
void buffer_del_line(Buffer buffer, Integer index, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
Array array = ARRAY_DICT_INIT;
|
||||
index = convert_index(index);
|
||||
@ -127,6 +130,7 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
|
||||
Boolean include_start,
|
||||
Boolean include_end,
|
||||
Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
start = convert_index(start) + !include_start;
|
||||
end = convert_index(end) + include_end;
|
||||
@ -235,6 +239,7 @@ void buffer_set_line_slice(Buffer buffer,
|
||||
Boolean include_end,
|
||||
ArrayOf(String) replacement,
|
||||
Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
start = convert_index(start) + !include_start;
|
||||
end = convert_index(end) + include_end;
|
||||
@ -590,6 +595,7 @@ void buffer_insert(Buffer buffer,
|
||||
Integer lnum,
|
||||
ArrayOf(String) lines,
|
||||
Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
// "lnum" will be the index of the line after inserting,
|
||||
// no matter if it is negative or not
|
||||
|
@ -48,6 +48,7 @@ void remote_ui_disconnect(uint64_t channel_id)
|
||||
|
||||
void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||
Dictionary options, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||
api_set_error(err, Exception, _("UI already attached for channel"));
|
||||
@ -117,6 +118,7 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||
}
|
||||
|
||||
void nvim_ui_detach(uint64_t channel_id, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
||||
@ -133,6 +135,7 @@ void ui_detach(uint64_t channel_id, Error *err)
|
||||
|
||||
void nvim_ui_try_resize(uint64_t channel_id, Integer width,
|
||||
Integer height, Error *err)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||
api_set_error(err, Exception, _("UI is not attached for channel"));
|
||||
@ -159,7 +162,9 @@ void ui_try_resize(uint64_t channel_id, Integer width,
|
||||
}
|
||||
|
||||
void nvim_ui_set_option(uint64_t channel_id, String name,
|
||||
Object value, Error *error) {
|
||||
Object value, Error *error)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||
api_set_error(error, Exception, _("UI is not attached for channel"));
|
||||
return;
|
||||
|
@ -583,6 +583,7 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)
|
||||
/// @param channel_id The channel id (passed automatically by the dispatcher)
|
||||
/// @param event The event type string
|
||||
void vim_subscribe(uint64_t channel_id, String event)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN);
|
||||
char e[METHOD_MAXLEN + 1];
|
||||
@ -596,6 +597,7 @@ void vim_subscribe(uint64_t channel_id, String event)
|
||||
/// @param channel_id The channel id (passed automatically by the dispatcher)
|
||||
/// @param event The event type string
|
||||
void vim_unsubscribe(uint64_t channel_id, String event)
|
||||
FUNC_API_NOEVAL
|
||||
{
|
||||
size_t length = (event.size < METHOD_MAXLEN ?
|
||||
event.size :
|
||||
@ -624,7 +626,7 @@ Dictionary vim_get_color_map(void)
|
||||
|
||||
|
||||
Array vim_get_api_info(uint64_t channel_id)
|
||||
FUNC_API_ASYNC
|
||||
FUNC_API_ASYNC FUNC_API_NOEVAL
|
||||
{
|
||||
Array rv = ARRAY_DICT_INIT;
|
||||
|
||||
|
@ -185,6 +185,7 @@
|
||||
#ifdef DEFINE_FUNC_ATTRIBUTES
|
||||
# define FUNC_API_ASYNC
|
||||
# define FUNC_API_NOEXPORT
|
||||
# define FUNC_API_NOEVAL
|
||||
# define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
|
||||
# define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x)
|
||||
# define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) REAL_FATTR_ALLOC_SIZE_PROD(x, y)
|
||||
|
Loading…
Reference in New Issue
Block a user