Skip to content

erts: Fix undefined behavior of driver start callback - #11435

Open
sverker wants to merge 2 commits into
erlang:masterfrom
sverker:sverker/erts/driver-start-args
Open

erts: Fix undefined behavior of driver start callback#11435
sverker wants to merge 2 commits into
erlang:masterfrom
sverker:sverker/erts/driver-start-args

Conversation

@sverker

@sverker sverker commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fix #11385

It's UB in C to call functions with too many arguments.

User drivers expect two arguments to start callback. Only call system drivers with the extra third argument.

It's UB in C to call functions with too many arguments.

User drivers expect two arguments to start() callback.
Only call system drivers with the extra third argument.
@sverker sverker self-assigned this Aug 6, 2026
@sverker sverker added team:VM Assigned to OTP team VM fix labels Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes undefined behavior in ERTS by ensuring the port driver start callback is invoked with the correct argument count: two arguments for normal/user drivers, and three arguments (including SysDriverOpts*) only for system drivers.

Changes:

  • Split driver start callbacks into start (2 args) and start_sys_drv (3 args) and call the appropriate one from erts_open_driver().
  • Extend internal driver initialization to classify system drivers and wire up the correct callback pointer.
  • Update driver entry documentation, but it currently drops important details about start error return conventions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
erts/emulator/beam/io.c Calls user-driver start with 2 args; calls system-driver start_sys_drv with SysDriverOpts*; updates driver initialization to set the right pointer.
erts/emulator/beam/global.h Adjusts internal erts_driver_t_ to store separate start vs start_sys_drv function pointers.
erts/doc/references/driver_entry.md Updates the documented ErlDrvEntry.start signature, but currently omits documented error return conventions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread erts/doc/references/driver_entry.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERTS calling driver callback through incompatible fp

2 participants