Skip to content

cpnet: make cpnet_newIPVxAddress() return NULL on failure - #84

Merged
guillerodriguez merged 1 commit into
masterfrom
fix/cpnet-new-address-null
Nov 6, 2026
Merged

guillerodriguez merged 1 commit into
masterfrom
fix/cpnet-new-address-null

Conversation

@guillerodriguez

Copy link
Copy Markdown
Contributor

Both cpnet_newIPV4Address() and cpnet_newIPV6Address() used the result of JCL_malloc() without checking it, so when the allocation failed they dereferenced NULL and crashed the VM. Make them return NULL on failure, with the OutOfMemoryError pending, and check the result in their callers:

  • cpnet_aton() returns ENOMEM. VMInetAddress.aton() now throws UnknownHostException only if no exception is pending, so the OutOfMemoryError is kept.
  • VMInetAddress.lookupInaddrAny(), VMInetAddress.getHostByAddr() and _javanet_get_ip_netaddr() release the address bytes and return with the OutOfMemoryError pending.

Both cpnet_newIPV4Address() and cpnet_newIPV6Address() used the
result of JCL_malloc() without checking it, so when the allocation
failed they dereferenced NULL and crashed the VM. Make them return
NULL on failure, with the OutOfMemoryError pending, and check the
result in their callers:

- cpnet_aton() returns ENOMEM. VMInetAddress.aton() now throws
  UnknownHostException only if no exception is pending, so the
  OutOfMemoryError is kept.
- VMInetAddress.lookupInaddrAny(), VMInetAddress.getHostByAddr()
  and _javanet_get_ip_netaddr() release the address bytes and return
  with the OutOfMemoryError pending.

Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
@guillerodriguez
guillerodriguez merged commit d0de59c into master Nov 6, 2026
3 checks passed
@guillerodriguez
guillerodriguez deleted the fix/cpnet-new-address-null branch November 6, 2026 07:47
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