fix: P0 safety fixes — OSAL header leak and const-cast UB#48
Merged
Conversation
claw_net.h is the OSAL network abstraction header and should not contain platform-conditional socket includes (lwip/sockets.h, sys/socket.h, etc.). This leaked platform details into any translation unit that included the header. Move the BSD socket includes directly into swarm.c, which is the only consumer outside the OSAL implementation files that needs them. The OSAL backends (claw_net_freertos.c, claw_net_rtthread.c) already include their own platform socket headers. Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
send_reply() splits long messages by temporarily inserting '\0' into a const char * parameter via (char *)p cast. This is undefined behavior per C99 — the underlying memory may be in a read-only segment. Replace the const-cast pattern with a heap-allocated chunk buffer (claw_malloc + memcpy) that is safely null-terminated and freed after each chunk is sent. Also add missing cJSON_IsString() check for message_type in feishu handle_message_event() to prevent NULL dereference if the field is not a string. Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
The message chunking algorithm (split at last newline before the length limit) was duplicated between feishu.c and telegram.c. Extract it into im_find_chunk_end() in a platform-independent im_util.c, and refactor both IM backends to call it. Add 14 unit tests covering: - no split needed (fits in max_chunk) - exact boundary - hard split when no newline found - split at last newline in scan range - multiple newlines (pick last before limit) - newline at max_chunk position (included) - newline in first half (outside scan, ignored) - single byte / zero remaining - full multi-round chunking simulation - degenerate max_chunk (1, 2) All 39 tests pass (make test-unit). Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
ESP32-S3 Xtensa QEMU emulation is 3-5x slower than ESP32-C3 RISC-V, causing the S3 smoke job to take 30+ minutes on GitHub Actions shared runners. Since C3 already covers the full ESP-IDF + FreeRTOS + OSAL path, the S3 difference is only in hardware peripherals which QEMU does not emulate anyway. Remove esp32s3-qemu from the per-PR ci-qemu-correctness matrix and create a dedicated ci-nightly.yml that runs it daily at 04:00 UTC. This cuts PR CI wall time from ~45 min to ~5 min. Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lwip/sockets.h/sys/socket.hvia#ifdef CLAW_PLATFORM_*, breaking the abstraction boundary. Moved BSD socket includes directly intoswarm.c(the only non-OSAL consumer).send_reply()cast awayconston aconst char *parameter to temporarily insert'\0'for chunk splitting. This is UB per C99. Replaced with heap-allocated chunk buffers (claw_malloc+memcpy). Also added missingcJSON_IsString()check in feishuhandle_message_event().Test plan
scripts/check-patch.shstyle check passesmake run-esp32c3-qemu