-
Notifications
You must be signed in to change notification settings - Fork 174
Component/net connect #939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| wifi_config.sta.channel = (uint8_t)(connect_args.channel->ival[0]); | ||
| } | ||
| const char *ssid = connect_args.ssid->sval[0]; | ||
| const char *pass = connect_args.password->sval[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unchecked Optional Argument Causes Undefined Behavior
Accessing connect_args.password->sval[0] without checking connect_args.password->count first causes undefined behavior when password is not provided. Since password is defined as arg_str0 (optional argument), the code must verify count > 0 before dereferencing sval[0], similar to how other optional arguments are handled in the codebase.
| // run getaddrinfo() to decide on the IP protocol | ||
| hints.ai_family = AF_UNSPEC; | ||
| hints.ai_socktype = sock_type; | ||
| hints.ai_protocol = IPPROTO_TCP; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Protocol Mismatch Breaks UDP Address Resolution
Hardcoding hints.ai_protocol = IPPROTO_TCP ignores the sock_type parameter. When sock_type is SOCK_DGRAM, the protocol should be IPPROTO_UDP or left unspecified to let getaddrinfo infer it from ai_socktype. This causes UDP socket address resolution to potentially fail or behave incorrectly.
|
|
||
| char *rest = NULL; | ||
| char *temp = strtok_r(buf, " ", &rest); | ||
| strncpy((char*)wifi_config.sta.ssid, temp, sizeof(wifi_config.sta.ssid)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Null Pointer Crash on Empty Input
Null pointer dereference when strtok_r returns NULL. If the user enters only whitespace or an empty line, strtok_r at line 225 returns NULL, causing strncpy at line 226 to crash with a null pointer dereference. The code should verify temp is not NULL before using it.
| ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, CONFIG_NET_CONNECT_CONNECT_UART_TX_PIN, CONFIG_NET_CONNECT_CONNECT_UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); | ||
| ESP_ERROR_CHECK(uart_set_rx_timeout(UART_NUM_1, 1)); | ||
|
|
||
| char *buffer = (char*)malloc(BUF_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unchecked Memory Allocation Leads to Instability
Missing null check after malloc(BUF_SIZE). If memory allocation fails, buffer will be NULL, causing crashes when used in subsequent operations like uart_read_bytes and ESP_LOG_BUFFER_HEXDUMP. The code should verify allocation succeeded before proceeding.
| s_stop_task = false; | ||
| if (xTaskCreate(ppp_task, "ppp connect", 4096, NULL, 5, NULL) != pdTRUE) { | ||
| ESP_LOGE(TAG, "Failed to create a ppp connection task"); | ||
| return ESP_FAIL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| esp_err_t ret = esp_wifi_connect(); | ||
| if (ret != ESP_OK) { | ||
| ESP_LOGE(TAG, "WiFi connect failed! ret:%x", ret); | ||
| return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Connection Failure Causes Resource Leaks
Resource leak when esp_wifi_connect fails. Event handlers registered at lines 149-154 are not unregistered before returning, and if wait is true, the semaphores created at lines 136-145 are not deleted. This causes handle and memory leaks on connection failure.
…ectivity Port the network connection functionality from esp-idf's protocol_examples_common component to esp-protocols as a standalone net_connect component. Changes: - Port all network connection code from esp-idf/examples/common_components/protocol_examples_common - Rename functions from example_* prefix to net_* prefix for consistency - Add unified API supporting WiFi, Ethernet, Thread, and PPP interfaces - Add comprehensive Kconfig options for all connection types - Add net_connect_example demonstrating component usage - Update component structure with proper CMakeLists.txt and idf_component.yml - Add README with usage instructions for all supported interfaces The component provides a unified interface for establishing network connectivity across multiple transport types, simplifying network setup in protocol examples and applications. Supported interfaces: - WiFi (Station mode with configurable scan methods) - Ethernet (EMAC and SPI-based) - Thread (IEEE802.15.4 native or RCP) - PPP (Point-to-Point Protocol over Serial/USB) All configuration is done via Kconfig menuconfig, making it easy to enable/disable specific interfaces and configure connection parameters.
24d6b84 to
712046b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| vSemaphoreDelete(s_semph_get_ip_addrs); | ||
| return ESP_ERR_NO_MEM; | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Double-free vulnerability in Ethernet connection failure
If xSemaphoreCreateBinary fails for s_semph_get_ip6_addrs, s_semph_get_ip_addrs is deleted but its static pointer is not set to NULL. This leaves a dangling pointer that causes a double-free if net_connect_ethernet_shutdown is called subsequently (e.g., during manual cleanup).
| #if CONFIG_NET_CONNECT_CONNECT_IPV6 | ||
| xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY); | ||
| #endif | ||
| return ESP_OK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /* tear down connection, release resources */ | ||
| void net_connect_thread_shutdown(void) | ||
| { | ||
| vTaskDelete(s_ot_task_handle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Shutdown function deletes calling task if uninitialized
vTaskDelete is called on s_ot_task_handle without checking if it is NULL. If the OpenThread task was not successfully created (e.g., due to net_connect failure), this deletes the calling task (such as the main task), causing an unexpected system termination.
Add new APIs for WiFi STA configuration: - net_configure_wifi_sta() for configuration - net_connect_wifi() for connection - net_disconnect_wifi() for disconnection Maintains backward compatibility with existing API.
- Remove redundant "CONNECT" prefix from all config option names - Simplify WiFi connection to always use new API with auto-configuration - Add backward compatibility mappings in sdkconfig.rename
Description
Related
Testing
Checklist
Before submitting a Pull Request, please ensure the following:
Note
Adds the
net_connectcomponent providing unified connect/disconnect APIs for WiFi/Ethernet/Thread/PPP, utilities, console commands, Kconfig, and an example app.net_connect(),net_disconnect(),net_get_netif_from_desc()and descriptors forsta/eth/thread/ppp.wifi_connect,wifi_disconnect).CMakeLists.txt,Kconfig.projbuildwith extensive options;idf_component.yml;sdkconfig.rename.examples/net_connect_exampleproject demonstrating initialization and usage.README.mddescribing interfaces and PPP setup..pre-commit-config.yaml: addnet_connectto allowed commit scopes.Written by Cursor Bugbot for commit 712046b. This will update automatically on new commits. Configure here.