summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-04-24treewide: fix issues reported by clang code analyzerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-24tests: allow executing run_tests.sh from any directoryJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-23Add initial GitLab and GitHub CI supportPetr Štetiar
Uses currently proof-of-concept openwrt-ci[1] in order to: * improve the quality of the codebase in various areas * decrease code review time and help merging contributions faster * get automagic feedback loop on various platforms and tools - out of tree build with OpenWrt SDK on following targets: * ath79-generic * imx6-generic * malta-be * mvebu-cortexa53 - out of tree native build on x86/64 with GCC (versions 8, 9, 10) and Clang 11 - out of tree native x86/64 static code analysis with cppcheck and scan-build from Clang 11 1. https://gitlab.com/ynezz/openwrt-ci/ Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: add more testsPetr Štetiar
* add cram based tests * test under either valgrind or LLVM sanitizers * add libFuzzer template Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: custom: return exit code if tests failsPetr Štetiar
Otherwise tests always pass in ctest. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: do not output binaries into lib directoryPetr Štetiar
It doesn't work properly with out of tree builds etc. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: create custom tests from current tests casesPetr Štetiar
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23main: provide just binary name in help outputPetr Štetiar
Otherwise it prints out complete path which is probably not desired and we would need to filter out paths in the test's output etc. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23lexer: fix incomplete struct initializersPetr Štetiar
Fixes bunch of following warnings: lexer.c:68:37: warning: missing field 'parse' initializer [-Wmissing-field-initializers] lexer.c:138:34: warning: missing field '' initializer [-Wmissing-field-initializers] Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: enable extra compiler checksPetr Štetiar
Let's enforce additional automatic checks enforced by the compiler in order to catch possible errors during compilation. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: fix includes and librariesPetr Štetiar
So it can be built out of the tree. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: make 3.0 minimum versionPetr Štetiar
Probably using 3.0+ features anyway and should silence following warning: CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-21lib: implement sleep(ms) functionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-01lib: allow parsing non-array, non-object value in json()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-31compiler: actually expand block scope fix to for/while alt syntaxJo-Philipp Wich
Fixes: 97bf297 ("compiler: ensure that alternative if/for/while syntax has own block scope") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-31compiler: ensure that alternative if/for/while syntax has own block scopeJo-Philipp Wich
The `if ...: endif`, `for ...: endfor`, `while ...: endwhile` etc. syntax statements are supposed to have their own lexical scope, like curly brace blocks in normal statements. Without this, local variable declarations within such blocks would incorrectly shift stack offsets for the remainder of the program. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-30tests: add missing test case for fixed switch codegenJo-Philipp Wich
Fixes: aa9621d ("compiler: rework switch statement code generation") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-29compiler: rework switch statement code generationJo-Philipp Wich
- Initialize stack slots belonging to skipped local variable declarations - Group switch case value tests after switch statement body Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-29vm: add trace mode instruction dump output fixesJo-Philipp Wich
- Fix an off-by-one when printing push/pop stack indexes - Properly print negative hexadecimal values Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-26vm: fix another for-loop memory leakJo-Philipp Wich
Fixes: 20a3763 ("vm: fix loop variable memory leak in NEXTK/NEXTKV instruction") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25vm: fix further memory leaks in trace modeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25vm: fix loop variable memory leak in NEXTK/NEXTKV instructionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25lib: prevent use-after-free after uc_shift()Jo-Philipp Wich
Make sure to increase the refcount of items being moved since the subsequent put operation will decrease it, prematurely freeing moved items which will lead to use-after-free errors later on. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25object: free prototype object when registering existing ressource typeJo-Philipp Wich
Fixes: a478510 ("object: prevent registering the same ressource type multiple times") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-24compiler: fix for/break miscompilationJo-Philipp Wich
When patching jump targets for break statments while compiling for-loop statments, jump beyond the instructions popping intermediate loop variables off the stack to fix a stack position mismatch between compiler and vm. Before that change, local loop body variables got popped twice, breaking the expected stack layout. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-24lib: fix value refcount of uc_unshift() return valueJo-Philipp Wich
The ref count of the unshifted value returned by uc_unshift() must be increased in order to prevent a subsequent double free within the VM when the value eventually goes out of scope. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23run_tests.sh: allow passing tests to run as argumentsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23compiler: fix another try/catch miscompilationJo-Philipp Wich
When skipping over the catch block of a try/catch statement, make sure to emit the jump after the try scope variables have been popped off the stack in order to prevent a stack position mismatch between compiler and vm. Fixes: 9ad9afb ("compiler: fix try/catch miscompilation") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23lib: fix passing uninitialized memory to sigprocmask()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23vm: fix leaking source context strings in trace modeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-22lib: use execvp() in system()Jo-Philipp Wich
Use execvp() instead of execv() to lookup the specified executable in $PATH. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-19value: fix accessing array indexes with non-numeric valuesJo-Philipp Wich
Since libjson-c's json_object_get_int64() returns 0 for any input value that has no integer representation, any kind of invalid array index incorrectly yielded the first array element. Fix this issue by explicitly converting string values and by rejecting any other kind of value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-12compiler: fix parsing of arrow functions with single expression bodyJo-Philipp Wich
Ensure that an arrow function body expression is parsed with P_ASSIGN precedence to not greedily consume comma expressions. This ensures that an expression like () => 1, 2 is parsed as function [() => 1], integer [2] and not as function [() => 1, 2]. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11lexer: fix infinite loop in lineinfo encoding when consuming large chunksJo-Philipp Wich
A logic flaw in the lineinfo encoding function led to an infinite tight loop when a buffer chunk with 128 byte or more got consumed, which may happen when parsing very long literals. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11lexer: properly handle string escape sequences at buffer boundaryJo-Philipp Wich
While parsing string literals, actually consume the backslash introducing an escape sequence to prevent it from ending up in the produced string if the scanner is at the end of the buffer and the remaining buffer contents are flushed after the consumer loop. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11object: prevent registering the same ressource type multiple timesJo-Philipp Wich
When a module registering custom ressource types, such as "fs.so", is required multiple times we need to ensure that only one instance of a given ressource type is registered, otherwise objects created after subsequent requires will cease to function since the internal type prototype mismatches. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11vm: gracefully handle property setting on non-array, non-object valuesJo-Philipp Wich
Before this fix, the VM aborted due to an assert in libjson-c when an attempt was made to set a property on a non-object value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11compiler: fix switch case->default fallthroughJo-Philipp Wich
Simplify handling of default case in switch statements. Instead of jumping over the default block, simply record the start address of the block since the initial switch jump is patched into the first non-default case already. This also leads to slightly smaller bytecode. Previously, when a case branch fell through into a default block, it did hit the default skip jump which jumped back into the first case which then fell through into the default skip jump, leading to an endless loop. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11run_tests.sh: add various fixes and improvementsJo-Philipp Wich
- Report encountered stderr/stdout when none is expected - Fix processing testcases where the code to run is defined first - Set module search path to source tree to enable loading C extensions Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-09lib: prevent possible use-after-free in uc_pop()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08object: remove unused struct memberJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08lib: retain prototype when passing scopes to include()Jo-Philipp Wich
Change uc_include() to retain the prototype of the given scope object when processing includes. Also change the default behaviour to register the current VM scope as prototype on the passed scope object so that included code has access to functions such as length(), print() etc. by default. To actually sandbox the included code, the new `proto()` function can be used to create a scope object with an empty prototype: `include(..., proto({ ... }, {}))` Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08main: expose global prototype as `global` property on root scopeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08lib: use uc_prototype_lookup() to obain search path property valueJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08vm: use uc_prototype_lookup() to obtain require function pointerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08object: introduce uc_prototype_lookup()Jo-Philipp Wich
The new uc_prototype_lookup() function allows looking up properties in the given prototype chain. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08fs: make error function available on directory, process and file handlesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08ubus: make error function available on the connection instanceJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08uci: fix potential invalid memory access in error()Jo-Philipp Wich
Check the numerical error code index before attempting to look it up in the error string array. Also make error function available on the cursor instance as well. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08fs: fix readlink() return valueJo-Philipp Wich
The fs.readlink() function incorrectly produced a JSON string containing trailing null bytes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>