Re: [PATCH] contrib: Honor symbolic port in git-credential-netrc.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Andreas Schwab <schwab@xxxxxxxxxxxxxx> writes:

> On Jun 20 2025, Junio C Hamano wrote:
>
>> Do we know symbolic port names are always limited to alnums?  Or on
>> some systems some byte values in the fringe, like "_" or "-", are
>> also allowed?
>
> Valid service names are documented in RFC6335.  Specifically it allows
> hyphens, but not underscores.

Thanks for the reference. I'm thinking at the moment to improve the
check for a valid port using something like this Scheme code:

--8<---------------cut here---------------start------------->8---
(define (port? port)
 "Return the numeric value for PORT, else #f."
 (if (and (exact-integer? port)
          (positive? port)
          (<= port (1- (expt 2 16))))
     port
     (catch 'system-error
      (lambda () (servent:port (getservbyname port "")))
      (const #f))))
scheme@(guile-user)> (port? "465")
$14 = #f
scheme@(guile-user)> (port? 465)
$15 = 465
scheme@(guile-user)> (port? "smtps")
$16 = 465
scheme@(guile-user)> (port? "unknown")
$17 = #f
scheme@(guile-user)> (port? 120000)
$18 = #f
--8<---------------cut here---------------end--------------->8---

So basically, try to call getservname(2) on a non-numeric port. If this
fails, the port is invalid, else return the port number.

-- 
Thanks,
Maxim




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux