Skip to content

Commit

Permalink
modules/linux: check that syscall number isn't nil
Browse files Browse the repository at this point in the history
The function would return 0 if passed a non-existent system call:
the table would return nil which is zero when reinterpreted as integer.
Now it handles the nil case properly by exiting with an error code.
  • Loading branch information
matheusmoreira committed Aug 11, 2024
1 parent 45c4450 commit 9ed5224
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions source/lone/lisp/modules/intrinsic/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void lone_lisp_modules_intrinsic_linux_initialize(struct lone_lisp *lone,
static inline long lone_lisp_value_to_linux_system_call_number(struct lone_lisp *lone,
struct lone_lisp_value linux_system_call_table, struct lone_lisp_value value)
{
struct lone_lisp_heap_value *actual;
struct lone_lisp_value number;

switch (value.type) {
case LONE_LISP_TYPE_INTEGER:
Expand All @@ -335,14 +335,12 @@ static inline long lone_lisp_value_to_linux_system_call_number(struct lone_lisp
break;
}

actual = value.as.heap_value;

switch (actual->type) {
switch (value.as.heap_value->type) {
case LONE_LISP_TYPE_TEXT:
value = lone_lisp_text_to_symbol(lone, value);
__attribute__((fallthrough));
case LONE_LISP_TYPE_SYMBOL:
return lone_lisp_table_get(lone, linux_system_call_table, value).as.integer;
number = lone_lisp_table_get(lone, linux_system_call_table, value);
case LONE_LISP_TYPE_BYTES:
case LONE_LISP_TYPE_MODULE:
case LONE_LISP_TYPE_FUNCTION:
Expand All @@ -352,6 +350,15 @@ static inline long lone_lisp_value_to_linux_system_call_number(struct lone_lisp
case LONE_LISP_TYPE_TABLE:
linux_exit(-1);
}

switch (number.type) {
case LONE_LISP_TYPE_INTEGER:
return value.as.integer;
case LONE_LISP_TYPE_NIL:
case LONE_LISP_TYPE_HEAP_VALUE:
case LONE_LISP_TYPE_POINTER:
linux_exit(-1);
}
}

static inline long lone_lisp_value_to_linux_system_call_argument(struct lone_lisp_value value)
Expand Down

0 comments on commit 9ed5224

Please sign in to comment.