Skip to content

Fix OpenVPN client: stack corruption, memory leak, key zeroing, dangling netif#128

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/check-openvpn-client-code
Draft

Fix OpenVPN client: stack corruption, memory leak, key zeroing, dangling netif#128
Copilot wants to merge 2 commits intomasterfrom
copilot/check-openvpn-client-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

Code review of the OpenVPN client implementation surfaced several bugs across the binding, adapter, and core layers.

Fixes

  • Lua stack corruption (luat_lib_netdrv.c): Extra lua_pop(L, 1) pops the config table before luat_netdrv_setup() consumes it — removed
  • Memory leak on register failure (luat_netdrv_openvpn.c): TLS contexts and cert buffers from ovpn_client_init() leaked when luat_netdrv_register() failed — added ovpn_client_stop() before free
  • Private key not wiped (luat_netdrv_openvpn_client.c): client_key_buf freed without zeroing — now uses mbedtls_platform_zeroize() to prevent key material lingering in heap
  • Dangling netif pointer (luat_netdrv_openvpn_client.c): net_lwip2_set_netif() not cleared on stop, leaving stale pointer in lwIP adapter table — added net_lwip2_set_netif(adapter_index, NULL)
  • Spurious disconnect event: OVPN_EVENT_DISCONNECTED fired even when client was never started — now gated on was_started
  • Dead code: Removed unused openvpn_shutdown() (defined but never wired to any netdrv callback)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ing netif, spurious event, dead code

Co-authored-by: wendal <589819+wendal@users.noreply.github.com>
Copilot AI changed the title [WIP] Review openvpn client implementation and suggest improvements Fix OpenVPN client: stack corruption, memory leak, key zeroing, dangling netif Mar 19, 2026
Copilot AI requested a review from wendal March 19, 2026 14:40
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants