summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2025-01-25Merge pull request #271 from jow-/socket-fixesJo-Philipp Wich
socket: fix AF_PACKET recvmsg() and sockaddr formatting
2025-01-25socket: fix AF_PACKET recvmsg() and sockaddr formattingJo-Philipp Wich
- Do not unconditionally pass the `MSG_CMSG_CLOEXEC` flag to `recvmsg()` invocations as not all protocol specific recvmsg implementations in the kernel tolerate it; `packet_recvmsg()` for example will immediately return yield `EINVAL` if any non-whitelisted flag is passed. - Ensure that the HW address string buffer is zero-terminated when converting MAC addresses from C to ucode values. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-01-24Merge pull request #270 from nbd168/argv0Jo-Philipp Wich
main: add global ARGV0 variable
2025-01-24main: add global SCRIPT_NAME variableFelix Fietkau
Fill it with the command line provided path to the source file Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-01-22Merge pull request #266 from aparcar/libmdJo-Philipp Wich
docs: Mention `libmd` in macOS docs
2025-01-22Merge pull request #267 from aparcar/macosJo-Philipp Wich
docs: Fix compilation command for macOS
2025-01-05docs: Fix compilation command for macOSPaul Spooren
Fixes: #265 "macOS build broken not finding libucode.0.dylib" Suggested-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Paul Spooren <mail@aparcar.org>
2025-01-05docs: Mention `libmd` in macOS docsPaul Spooren
Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-12-31Merge pull request #262 from stokito/patch-1Jo-Philipp Wich
debian/control: libucode Recommends ucode-modules
2024-12-31debian/control: libucode Recommends ucode-modulesSergey Ponomarev
2024-12-31Merge pull request #261 from stokito/patch-1Jo-Philipp Wich
debian/control: Build-Depend on cmake
2024-12-31debian/source/format: change to nativeSergey Ponomarev
2024-12-31debian/control: Fix Standards-Version, add BugsSergey Ponomarev
2024-12-31debian/control: Build-Depend on cmakeSergey Ponomarev
2024-12-31Merge pull request #260 from jow-/struct-memory-fixesJo-Philipp Wich
struct: fix memory leak in buffer.pull()
2024-12-30struct: fix memory leak in buffer.pull()Jo-Philipp Wich
Do not increase the refcount when returning the pulled buffer contents as string since the returned value already is the sole reference. Without this change, pulled buffer contents will be leaked whenever the `pull()` function is used. Also ensure that the buffer memory is completely zero initialized when it is allocated from scratch, the existing logic only cleared the trailing data area on reallocations but never the head on fresh allocations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-13Merge pull request #258 from jow-/uci-no-globalsJo-Philipp Wich
uci: eliminate usage of global variables
2024-12-12uci: eliminate usage of global variablesJo-Philipp Wich
Use the VM registry to store the last uci error code and lookup the uci cursor resource type at resource creation time instead of caching it in a global variable. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-11vm: close signal pipe in uc_vm_signal_handlers_reset()Jo-Philipp Wich
The previously introduced signal handler restoration logic did not take the signal dispatching pipe into account. Extend the `uc_vm_signal_handlers_reset()` function to also close any related pipe handles. Fixes: #255 Fixes: f9d2faf ("vm: reset signals when freeing VM") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-11Merge pull request #256 from nbd168/pretty-printJo-Philipp Wich
main: fix crash on printing -p output
2024-12-08main: fix crash on printing -p outputFelix Fietkau
Delete a duplicate ucv_put() line that can lead to a double-free bug. Reproduced by running: ucode -l nl80211 -p 'sprintf("%.J\n", nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, nl80211.const.NLM_F_DUMP, { wiphy: 0, split_wiphy_dump: true }))' Fixes: 0a7ff4715cb8 ("main: pretty-print `-p` output by default") Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-12-07tests: adjust testcases after previous commitJo-Philipp Wich
Reenabling signal dispatching caused a new object allocation so update the expected GC counts in the testcases. Fixes: a362263 ("vm: fix inverted condition in uc_vm_signal_handlers_setup()") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-07vm: fix inverted condition in uc_vm_signal_handlers_setup()Jo-Philipp Wich
The previous code refactoring inadvertently broke the signal setup condition check. Fixes: #254 Fixes: f9d2faf ("vm: reset signals when freeing VM") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #209 from jow-/struct-bufferJo-Philipp Wich
struct: Add new buffer API for incremental packing/unpacking
2024-12-06struct: do not use global variables for caching typesJo-Philipp Wich
Drop the usage of global static variables for caching the per-VM resource type objects in order to properly support loading the library in multiple concurrent threads or VM instances. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #252 from jow-/main-pretty-print-by-defaultJo-Philipp Wich
main: pretty-print `-p` output by default
2024-12-06struct: Add new buffer API for incremental packing/unpackingJo-Philipp Wich
Implement a new struct buffer API to support incremental packing and unpacking of binary data. This API allows for more flexible and efficient handling of structured data, especially for streaming or partial processing scenarios. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #251 from jow-/fix-parsing-kwlabels-after-commentsJo-Philipp Wich
lexer: Preserve keyword, regexp flags until processing non-comment to…
2024-12-06main: pretty-print `-p` output by defaultJo-Philipp Wich
When outputting non-string expression results while running the cli interpreter using the `-p` flag, pretty-print the resulting JSON data for better readability. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06lexer: Preserve keyword, regexp flags until processing non-comment tokensJo-Philipp Wich
When the lexer has either the `no_keyword` or `no_regexp` flag set, it should retain these flags until it encounters a non-comment token. Only then should it stop preventing the interpretation of tokens beginning with a letter or forward slash as keywords or regular expression literals, respectively. Previously, these flags were being reset too early when processing comments, which could cause incorrect parsing when comments appeared between relevant tokens. The flags should only be reset after consuming an actual non-comment token to ensure consistent parsing behavior. Fixes: #250 Fixes: 855854f ("lexer: emit comment and template statement block tokens") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-05Merge pull request #249 from jow-/nl80211-single-split-wiphy-dumpJo-Philipp Wich
nl80211: properly support split_wiphy_dump for single phys
2024-12-05nl80211: properly support split_wiphy_dump for single physJo-Philipp Wich
When performing a `NL80211_CMD_GET_WIPHY` request for a single wiphy with `split_wiphy_dump` set to true, the expectation is that only a single phy object is returned, like when performing the same request without splitting, yet the current implementation returns a sparse array with only the requested phy index populated instead. Fix this issue by special-casing NL80211_CMD_GET_WIPHY command requests with a set `split_wiphy_dump` attribute. Also implicitly set the `NLM_F_DUMP` flag in this case as it is required for the kernel to send all information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-04types: ucv_resource_create(): rename `typename` parameter to `type`Jo-Philipp Wich
Since `typename` is a reserved word in C++ avoid using it to allow successful compilation with a C++ compiler. Fixes: #248 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02Merge pull request #247 from jow-/lib-use-sort-rJo-Philipp Wich
lib: utilize `ucv_array_sort_r()` and `ucv_object_sort_r()`
2024-12-02lib: utilize `ucv_array_sort_r()` and `ucv_object_sort_r()`Jo-Philipp Wich
Utilize the newly introduced sort functions to eliminate the global sort context usage. This change was originally part of PR #242 but got dropped during refactoring. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02Merge pull request #242 from IdWV/global-variablesJo-Philipp Wich
Removed all global variables from libucode for thread safety
2024-12-02vm: reset signals when freeing VMJo-Philipp Wich
When invoking `uc_vm_free()` on a VM with enabled `.setup_signal_handlers` configuration, reset system signal handlers back to their default actions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02types, vm: refactor usage of global variablesJo-Philipp Wich
Introduce an extensible private TLS context structure and use it within libucode to store global state such as active object iterators. This allows using libucode concurrently in multiple threads without unintentionally sharing global state among them. Also adjust the signal dispatching setup logic in `uc_vm_init()` to only enable signal handling if no other VM in the same thread already handles signals. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [squash commits, move signal handler vm pointer and object iterator list into common extensible TLS context, whitespace and naming adjustments, extended signal setup logic] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-02types: introduce `ucv_array_sort_r()` and `ucv_object_sort_r()`Jo-Philipp Wich
Introduce two new functions for ordering arrays and object keys which utilize a different compare callback signature and allow passing a user provided pointer to the comparison callback. The main advantages of the `ucv_*_sort_r()` flavors are the ability to pass custom context to comparisons via the user data pointer and the invocation of the comparison callback with direct `uc_value_t *` pointers instead of opaque `const void *` arguments pointing to `uc_value_t *` or json-c internal `struct lh_entry *` pointers respectively. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [align naming and whitespace with the rest of the codebase, rename some variables for clarity, group sort related changes into two commits, drop constness from `uc_value_t *` compare function arguments] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01Merge pull request #234 from IdWV/fsJo-Philipp Wich
lib: Removed global variables from module fs for thread safety
2024-12-01Merge pull request #232 from sebastianertz/lib-digestJo-Philipp Wich
lib: introduce digest library
2024-12-01digest: implement compile time option to exclude less common algorithmsJo-Philipp Wich
Introduce a new default enabled CMake option `DIGEST_SUPPORT_EXTENDED` which, when turned off, disables all but the most common md5, sha1 and sha256 alogirthms to reduce the library size. Also prefer statically linking libmd if possible. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01ci: include libmd in MacOS CI buildsJo-Philipp Wich
This is needed for the upcoming digest library support. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-01lib: introduce digest librarySebastian Ertz
Signed-off-by: Sebastian Ertz <sebastian.ertz@gmx.de>
2024-11-29Merge pull request #246 from jow-/fix-upvalue-resolveJo-Philipp Wich
vm: resolve upvalues before pushing them onto the stack
2024-11-29types: resolve upvalue values in arrays and objectsJo-Philipp Wich
Some objects, such as wildcard module import namespace dictionaries may contain upvalue type values. Extend `ucv_key_get()` to transparently resolve such values before returning them to the caller in order to avoid increasing the refcount of the upvalue itself, leading to a memory leak later on when the VM indirectly dereferences it on upon `uc_vm_stack_push()`, loosing the upvalue object reference itself in the process. This long standing leak was discovered while fixing another upvalue related module import quirk. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-11-29vm: resolve upvalues before pushing them onto the stackJo-Philipp Wich
Commit e5fe6b1 ("treewide: refactor vector usage code") accidentially dropped the upvalue resolving logic from uc_vm_stack_push(), leading to unresolved upvalues leaking into the script execution context. Fixes: e5fe6b1 ("treewide: refactor vector usage code") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-11-29ci: drop OpenWrt tests for nowJo-Philipp Wich
The OpenWrt CI runs are broken and need to be redone. In order to unblock the PR pipeline, drop these tests for now to reintroduce fixed variants at a later point in time. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-24fs: eliminate the usage of global variablesIsaac de Wolff
Move last error code into a VM registry value and lookup resource types within the current VM context at call time, allowing the proper use of the fs module within multiple threads of a multithreaded application. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [turn err_return() back into a local macro, simplify uc_fs_error(), align whitespace style] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-24types: add ucv_resource_create() helperJo-Philipp Wich
Introduce a new inline convenience function ucv_resource_create() which simplifies creating resource values by resource type name by combining resource type lookup and resource value creation in one call. This function will be used in subsequent refactoring to eliminate global static variables. Suggested-by: Isaac de Wolff <idewolff@vincitech.nl> [separated from original commit, move ucv_resource_create() into types.h] Signed-off-by: Jo-Philipp Wich <jo@mein.io>