emacs-devel
[Top][All Lists]
Advanced

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

Error checking in format-network-address


From: Juanma Barranquero
Subject: Error checking in format-network-address
Date: Tue, 27 Mar 2007 18:04:21 +0200

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 via email to

[Prev in Thread] Current Thread [Next in Thread]