* Error checking in format-network-address
@ 2007-03-27 16:04 Juanma Barranquero
2007-03-27 16:15 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Juanma Barranquero @ 2007-03-27 16:04 UTC (permalink / raw)
To: Emacs-Devel
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);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Error checking in format-network-address
2007-03-27 16:04 Error checking in format-network-address Juanma Barranquero
@ 2007-03-27 16:15 ` Andreas Schwab
2007-03-27 19:41 ` Juanma Barranquero
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2007-03-27 16:15 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Emacs-Devel
"Juanma Barranquero" <lekktu@gmail.com> writes:
> 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]);
Better use EMACS_INT here.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-03-27 19:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-27 16:04 Error checking in format-network-address Juanma Barranquero
2007-03-27 16:15 ` Andreas Schwab
2007-03-27 19:41 ` Juanma Barranquero
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.