From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.devel Subject: Error checking in format-network-address Date: Tue, 27 Mar 2007 18:04:21 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1175011481 17971 80.91.229.12 (27 Mar 2007 16:04:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 27 Mar 2007 16:04:41 +0000 (UTC) To: Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 27 18:04:33 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HWE9w-0004M2-L5 for ged-emacs-devel@m.gmane.org; Tue, 27 Mar 2007 18:04:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HWECJ-0008JE-Aa for ged-emacs-devel@m.gmane.org; Tue, 27 Mar 2007 11:06:59 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HWECF-0008GO-EW for emacs-devel@gnu.org; Tue, 27 Mar 2007 12:06:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HWECD-0008Be-Oy for emacs-devel@gnu.org; Tue, 27 Mar 2007 12:06:54 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HWECD-0008BG-KR for emacs-devel@gnu.org; Tue, 27 Mar 2007 11:06:53 -0500 Original-Received: from nz-out-0506.google.com ([64.233.162.235]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HWE9q-000505-4s for emacs-devel@gnu.org; Tue, 27 Mar 2007 12:04:26 -0400 Original-Received: by nz-out-0506.google.com with SMTP id s1so1761684nze for ; Tue, 27 Mar 2007 09:04:25 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Temi/1XjlvdY03tf9wlhQSBE2zhoarsvdGhBslxbwg8f0Lm3J3EmVMWus/0bTxxQaP1S4K5AR9mA2OSg0XDb8Wdtc/tGtLkT495CfoUo7/XWSVhXv8SwvSt9t5LU8l21Vt7OMSopr6bpOnydeK4cSMVAxJqY/v+Mh27449JKffI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=AxkbB1JNTvwzkhgvgCatoogpj8lmX0yR0o30CY9LMlaEvLs53/06ZN35U705Rq67es8lWjCUckK75be1ubyVm5ZveRMcdk3QelPoJNSc6dAvulUQZJ5lfamUtcdqxGUtxyd0CJNiIBUtW2dTsowpBvFugc6cwR+6HD/YW15ACf8= Original-Received: by 10.114.26.1 with SMTP id 1mr3206296waz.1175011461660; Tue, 27 Mar 2007 09:04:21 -0700 (PDT) Original-Received: by 10.114.234.16 with HTTP; Tue, 27 Mar 2007 09:04:21 -0700 (PDT) Content-Disposition: inline X-detected-kernel: Linux 2.4-2.6 (Google crawlbot) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:68671 Archived-At: The docstring for `format-network-address' says: "Returns nil if format of address is invalid." However, the function does not do much error checking, other than rejecting nil arguments and vectors not of the right size. It blindingly accepts absurd IP addresses, though: ELISP> (format-network-address [0 256 -256 100000 -7]) "0.256.-256.100000:-7" ELISP> (format-network-address [1 2 3 4 5 6 -777777 88888888]) "1:2:3:4:5:6:1ff421cf:54c5638" I suggest the attached patch, which forces the function to return nil for such pathological cases. The function accepts also cons pairs and strings with no almost no error checking whatsoever: ELISP> (format-network-address "any:stuff") "any:stuff" ELISP> (format-network-address (cons -100 'stuff)) "" but as those format are not documented I suppose they're OK. Juanma Index: src/process.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/process.c,v retrieving revision 1.508 diff -u -2 -r1.508 process.c --- src/process.c 27 Mar 2007 15:19:33 -0000 1.508 +++ src/process.c 27 Mar 2007 15:38:12 -0000 @@ -1296,5 +1296,18 @@ for (i = 0; i < nargs; i++) - args[i+1] = p->contents[i]; + { + int element = XINT (p->contents[i]); + + if (element < 0 || element > 65535) + return Qnil; + + if ((nargs < 8) /* IPv4 */ + && (i < 4) /* host, not port */ + && (element > 255)) + return Qnil; + + args[i+1] = p->contents[i]; + } + return Fformat (nargs+1, args); }