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:
Björn Linse 2016-06-20 14:40:57 +02:00
parent 7e2348f2b1
commit e536abc1e1
6 changed files with 35 additions and 18 deletions

View File

@ -37,6 +37,7 @@ c_proto = Ct(
Cg(Cc(false), 'async') * Cg(Cc(false), 'async') *
(fill * Cg((P('FUNC_API_ASYNC') * Cc(true)), 'async') ^ -1) * (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_NOEXPORT') * Cc(true)), 'noexport') ^ -1) *
(fill * Cg((P('FUNC_API_NOEVAL') * Cc(true)), 'noeval') ^ -1) *
fill * P(';') fill * P(';')
) )
grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1) grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1)

View File

@ -25,11 +25,13 @@ local gperfpipe = io.open(funcsfname .. '.gperf', 'wb')
local funcs = require('eval').funcs local funcs = require('eval').funcs
local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all")) local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all"))
for i,fun in ipairs(metadata) do for i,fun in ipairs(metadata) do
funcs['api_'..fun.name] = { if not fun.noeval then
args=#fun.parameters, funcs['api_'..fun.name] = {
func='api_wrapper', args=#fun.parameters,
data='&handle_'..fun.name, func='api_wrapper',
} data='&handle_'..fun.name,
}
end
end end
local funcsdata = io.open(funcs_file, 'w') local funcsdata = io.open(funcs_file, 'w')

View File

@ -56,6 +56,7 @@ Integer buffer_line_count(Buffer buffer, Error *err)
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
/// @return The line string /// @return The line string
String buffer_get_line(Buffer buffer, Integer index, Error *err) String buffer_get_line(Buffer buffer, Integer index, Error *err)
FUNC_API_NOEVAL
{ {
String rv = { .size = 0 }; String rv = { .size = 0 };
@ -84,6 +85,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// @param line The new line. /// @param line The new line.
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
FUNC_API_NOEVAL
{ {
Object l = STRING_OBJ(line); Object l = STRING_OBJ(line);
Array array = { .items = &l, .size = 1 }; 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 index The line index
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
void buffer_del_line(Buffer buffer, Integer index, Error *err) void buffer_del_line(Buffer buffer, Integer index, Error *err)
FUNC_API_NOEVAL
{ {
Array array = ARRAY_DICT_INIT; Array array = ARRAY_DICT_INIT;
index = convert_index(index); index = convert_index(index);
@ -122,11 +125,12 @@ void buffer_del_line(Buffer buffer, Integer index, Error *err)
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
/// @return An array of lines /// @return An array of lines
ArrayOf(String) buffer_get_line_slice(Buffer buffer, ArrayOf(String) buffer_get_line_slice(Buffer buffer,
Integer start, Integer start,
Integer end, Integer end,
Boolean include_start, Boolean include_start,
Boolean include_end, Boolean include_end,
Error *err) Error *err)
FUNC_API_NOEVAL
{ {
start = convert_index(start) + !include_start; start = convert_index(start) + !include_start;
end = convert_index(end) + include_end; end = convert_index(end) + include_end;
@ -229,12 +233,13 @@ end:
// array will simply delete the line range) // array will simply delete the line range)
/// @param[out] err Details of an error that may have occurred /// @param[out] err Details of an error that may have occurred
void buffer_set_line_slice(Buffer buffer, void buffer_set_line_slice(Buffer buffer,
Integer start, Integer start,
Integer end, Integer end,
Boolean include_start, Boolean include_start,
Boolean include_end, Boolean include_end,
ArrayOf(String) replacement, ArrayOf(String) replacement,
Error *err) Error *err)
FUNC_API_NOEVAL
{ {
start = convert_index(start) + !include_start; start = convert_index(start) + !include_start;
end = convert_index(end) + include_end; end = convert_index(end) + include_end;
@ -590,6 +595,7 @@ void buffer_insert(Buffer buffer,
Integer lnum, Integer lnum,
ArrayOf(String) lines, ArrayOf(String) lines,
Error *err) Error *err)
FUNC_API_NOEVAL
{ {
// "lnum" will be the index of the line after inserting, // "lnum" will be the index of the line after inserting,
// no matter if it is negative or not // no matter if it is negative or not

View File

@ -48,6 +48,7 @@ void remote_ui_disconnect(uint64_t channel_id)
void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
Dictionary options, Error *err) Dictionary options, Error *err)
FUNC_API_NOEVAL
{ {
if (pmap_has(uint64_t)(connected_uis, channel_id)) { if (pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI already attached for channel")); 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) void nvim_ui_detach(uint64_t channel_id, Error *err)
FUNC_API_NOEVAL
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI is not attached for channel")); 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, void nvim_ui_try_resize(uint64_t channel_id, Integer width,
Integer height, Error *err) Integer height, Error *err)
FUNC_API_NOEVAL
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI is not attached for channel")); 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, 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)) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(error, Exception, _("UI is not attached for channel")); api_set_error(error, Exception, _("UI is not attached for channel"));
return; return;

View File

@ -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 channel_id The channel id (passed automatically by the dispatcher)
/// @param event The event type string /// @param event The event type string
void vim_subscribe(uint64_t channel_id, String event) void vim_subscribe(uint64_t channel_id, String event)
FUNC_API_NOEVAL
{ {
size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN); size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN);
char e[METHOD_MAXLEN + 1]; 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 channel_id The channel id (passed automatically by the dispatcher)
/// @param event The event type string /// @param event The event type string
void vim_unsubscribe(uint64_t channel_id, String event) void vim_unsubscribe(uint64_t channel_id, String event)
FUNC_API_NOEVAL
{ {
size_t length = (event.size < METHOD_MAXLEN ? size_t length = (event.size < METHOD_MAXLEN ?
event.size : event.size :
@ -624,7 +626,7 @@ Dictionary vim_get_color_map(void)
Array vim_get_api_info(uint64_t channel_id) Array vim_get_api_info(uint64_t channel_id)
FUNC_API_ASYNC FUNC_API_ASYNC FUNC_API_NOEVAL
{ {
Array rv = ARRAY_DICT_INIT; Array rv = ARRAY_DICT_INIT;

View File

@ -185,6 +185,7 @@
#ifdef DEFINE_FUNC_ATTRIBUTES #ifdef DEFINE_FUNC_ATTRIBUTES
# define FUNC_API_ASYNC # define FUNC_API_ASYNC
# define FUNC_API_NOEXPORT # define FUNC_API_NOEXPORT
# define FUNC_API_NOEVAL
# define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC # define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
# define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x) # 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) # define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) REAL_FATTR_ALLOC_SIZE_PROD(x, y)