@@ -22,6 +22,13 @@ export const DEFAULT_PARKING_HOST = "moshcoding.com";
2222export const DEFAULT_PORT = 5354 ;
2323export const DEFAULT_HOST = "127.0.0.1" ;
2424
25+ export function parseDnsPort ( input ) {
26+ const raw = String ( input ?? "" ) . trim ( ) ;
27+ if ( ! / ^ \d + $ / . test ( raw ) ) return null ;
28+ const port = Number ( raw ) ;
29+ return Number . isSafeInteger ( port ) && port >= 1 && port <= 65535 ? port : null ;
30+ }
31+
2532// Short, because a name's target can change the moment its owner points it
2633// somewhere. A stale A record is the one failure mode users cannot debug.
2734export const DEFAULT_TTL = 30 ;
@@ -377,14 +384,21 @@ export async function dnsCommand(args = [], out = console.log) {
377384 const i = rest . indexOf ( `--${ name } ` ) ;
378385 return i >= 0 && rest [ i + 1 ] ? rest [ i + 1 ] : fallback ;
379386 } ;
380- const port = Number ( flag ( "port" , DEFAULT_PORT ) ) ;
381387 const registryBase = flag ( "registry" , DEFAULT_REGISTRY_BASE ) ;
382388
383389 if ( ! sub || sub === "help" || sub === "--help" ) {
384390 out ( USAGE ) ;
385391 return 0 ;
386392 }
387393
394+ const portIndex = rest . indexOf ( "--port" ) ;
395+ const rawPort = portIndex >= 0 ? rest [ portIndex + 1 ] : DEFAULT_PORT ;
396+ const port = parseDnsPort ( rawPort ) ;
397+ if ( port === null ) {
398+ out ( `--port needs a decimal integer from 1 to 65535, got ${ JSON . stringify ( rawPort ) } ` ) ;
399+ return 1 ;
400+ }
401+
388402 if ( sub === "tlds" ) {
389403 const tlds = await fetchTlds ( { registryBase } ) ;
390404 out ( tlds . length ? tlds . map ( ( t ) => `.${ t } ` ) . join ( "\n" ) : "no TLDs claimed yet" ) ;
@@ -428,7 +442,13 @@ export async function dnsCommand(args = [], out = console.log) {
428442 // by Host header and 404s a name it has never heard of, so pointing at
429443 // loopback — where the responder below is listening — is the difference
430444 // between `curl <name>` resolving and `curl <name>` working.
431- const parkingHttpPort = Number ( flag ( "parking-port" , DEFAULT_PARKING_HTTP_PORT ) ) ;
445+ const parkingPortIndex = rest . indexOf ( "--parking-port" ) ;
446+ const rawParkingHttpPort = parkingPortIndex >= 0 ? rest [ parkingPortIndex + 1 ] : DEFAULT_PARKING_HTTP_PORT ;
447+ const parkingHttpPort = parseDnsPort ( rawParkingHttpPort ) ;
448+ if ( parkingHttpPort === null ) {
449+ out ( `--parking-port needs a decimal integer from 1 to 65535, got ${ JSON . stringify ( rawParkingHttpPort ) } ` ) ;
450+ return 1 ;
451+ }
432452 let parking = null ;
433453 if ( ! rest . includes ( "--no-parking-http" ) ) {
434454 try {
0 commit comments