all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Juanma Barranquero" <lekktu@gmail.com>
To: Emacs-Devel <emacs-devel@gnu.org>
Subject: Error checking in format-network-address
Date: Tue, 27 Mar 2007 18:04:21 +0200	[thread overview]
Message-ID: <f7ccd24b0703270904r89c9c15j1046be89acd21cf8@mail.gmail.com> (raw)

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))
"<Family -100>"

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);
     }

             reply	other threads:[~2007-03-27 16:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-27 16:04 Juanma Barranquero [this message]
2007-03-27 16:15 ` Error checking in format-network-address Andreas Schwab
2007-03-27 19:41   ` Juanma Barranquero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7ccd24b0703270904r89c9c15j1046be89acd21cf8@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.