Skip to content

Check port parameter value in listen() in UDPServer and TCPServer - #120522

Open
NoNormalDev wants to merge 2 commits into
godotengine:masterfrom
NoNormalDev:listenport
Open

Check port parameter value in listen() in UDPServer and TCPServer#120522
NoNormalDev wants to merge 2 commits into
godotengine:masterfrom
NoNormalDev:listenport

Conversation

@NoNormalDev

@NoNormalDev NoNormalDev commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

What problem(s) does this PR solve?

Additional information

Changed the parameter type of port to int64_t (a 64-bit signed integer, the same type as int in GDScript).
Performs a check if the value is in the range 0-65535 (inclusive).

@NoNormalDev
NoNormalDev requested a review from a team as a code owner June 21, 2026 16:15
@NoNormalDev
NoNormalDev marked this pull request as draft June 21, 2026 16:32
@AThousandShips
AThousandShips requested a review from a team June 22, 2026 08:23
@AThousandShips AThousandShips added this to the 4.x milestone Jun 22, 2026
@NoNormalDev

This comment was marked as resolved.

@Ivorforce

Copy link
Copy Markdown
Member

EDIT: This solution breaks compatibility for GDExtensions, will see what can I do about that.

Can't seem to find a way to get around this, so I think that this is going to be for Godot 5.x

It's solvable. See https://docs.godotengine.org/en/stable/engine_details/development/handling_compatibility_breakages.html (and the various API-break examples throughout the codebase).

@NoNormalDev NoNormalDev changed the title Check port parameter value in listen(), in UDPServer and TCPServer to avoid integer underflow/overflow Check port parameter value in listen() in UDPServer and TCPServer Jun 22, 2026
Comment thread core/io/tcp_server.cpp Outdated
Comment thread core/io/udp_server.cpp Outdated
@NoNormalDev
NoNormalDev force-pushed the listenport branch 3 times, most recently from 0bbf2ee to 0399a77 Compare July 1, 2026 10:50
@NoNormalDev
NoNormalDev marked this pull request as ready for review July 1, 2026 10:50
@NoNormalDev
NoNormalDev requested review from a team as code owners July 1, 2026 10:50
Comment on lines +4 to +7
Validate extension JSON: Error: Field 'classes/TCPServer/methods/listen/arguments/0': meta changed value in new API, from "uint16" to "int64".
Validate extension JSON: Error: Field 'classes/UDPServer/methods/listen/arguments/0': meta changed value in new API, from "uint16" to "int64".

Changed the "port" parameter type in TCPServer.listen() and UDPServer.listen() from uint16_t to int64_t. Now it checks if it lies in the range 0-65535, and returns an error if not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you need to provide compat methods, even though the underlying Variant type will be the same, because of ptrcall and call implications.

cc @dsnopek

@NoNormalDev NoNormalDev Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've removed the compat methods based on https://chat.godotengine.org/channel/new-contributors?msg=aT4RZYy2hKmDX6AWd, which fixed the checks failing... Really unsure now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added back the compat methods, and now .NET is complaining...

@Faless

Faless commented Aug 23, 2026 via email

Copy link
Copy Markdown
Collaborator

@NoNormalDev

Copy link
Copy Markdown
Contributor Author

What's the reason for changing uint64_t to int64_t (which in turn forces us to add a compatibility method), instead of just checking < 65535? Ciao, Fabio

Hi, well it's a change from uint16, not uint64.

@Faless

Faless commented Aug 23, 2026 via email

Copy link
Copy Markdown
Collaborator

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UDPServer.listen() and TCPServer.listen() accept port numbers outside of the 0-65535 range

5 participants