From owner-freebsd-hackers Wed Jan 22 21:49:40 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7164F37B405 for ; Wed, 22 Jan 2003 21:49:39 -0800 (PST) Received: from smtp.netli.com (ip2-pal-focal.netli.com [66.243.52.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 527B243F3F for ; Wed, 22 Jan 2003 21:49:38 -0800 (PST) (envelope-from vlm@netli.com) Received: (qmail 11435 invoked by uid 84); 23 Jan 2003 05:49:25 -0000 Received: from vlm@netli.com by l3-1 with qmail-scanner-0.96 (uvscan: v4.1.40/v4121. . Clean. Processed in 0.119551 secs); 23 Jan 2003 05:49:25 -0000 Received: from unknown (HELO netli.com) (192.168.238.32) by mx01-pal-lan.netli.lan with SMTP; 23 Jan 2003 05:49:25 -0000 Message-ID: <3E2F8250.3080300@netli.com> Date: Wed, 22 Jan 2003 21:49:04 -0800 From: Lev Walkin Organization: Netli, Inc. User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.1) Gecko/20021117 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Giorgos Keramidas Cc: hackers@freebsd.org Subject: Re: Checking sockaddr_in port number for overflow References: <20030123025437.GA40516@gothmog.gr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Giorgos Keramidas wrote: > I have been trying to think of a good way to check for overflow of > port numbers of PF_INET sockets that are passed by the user. So far, > this is what I have come up with: > > : > : errno == 0; > : tmp = strtol(argv[1], &errp, 0); > : if (errp == argv[1] || errno == EINVAL || errno == ERANGE) > : errx(1, "invalid number '%s'", argv[1]); > : if (tmp > IPPORT_MAX) > : errx(1, "%ld will overflow as a port number (max %d)", > : tmp, IPPORT_MAX); > > Does this look ok to you all? > Have I missed anything obvious that I should also check? tmp <= 0. -- Lev Walkin vlm@netli.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message