1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: check invalid port number (#15016)

This commit is contained in:
yuyi 2022-07-11 12:55:33 +08:00 committed by GitHub
parent bfcf5b13ed
commit cc43a23f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -384,6 +384,9 @@ pub struct RunParams {
// Example: vweb.run_at(app, 'localhost', 8099) // Example: vweb.run_at(app, 'localhost', 8099)
[manualfree] [manualfree]
pub fn run_at<T>(global_app &T, params RunParams) ? { pub fn run_at<T>(global_app &T, params RunParams) ? {
if params.port <= 0 || params.port > 65535 {
return error('invalid port number `$params.port`, it should be between 1 and 65535')
}
mut l := net.listen_tcp(params.family, '$params.host:$params.port') or { mut l := net.listen_tcp(params.family, '$params.host:$params.port') or {
ecode := err.code() ecode := err.code()
return error('failed to listen $ecode $err') return error('failed to listen $ecode $err')