summaryrefslogtreecommitdiff
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-05-14 18:44:36 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-05-14 18:48:59 -0700
commitd23a486ba27405acfda67a4dc387ade5e399a29b (patch)
tree6e7a2dc2d896e78194d049c4a54eae832a3b0040 /src/process.c
parente6f64df9c2b443d3385c2c25c29ccd5283d37e3f (diff)
downloademacs-d23a486ba27405acfda67a4dc387ade5e399a29b.tar.gz
Fix address violation found by AddressSanitizer
* src/process.c (connect_network_socket): Use struct sockaddr_storage, not struct sockaddr_in, to store info about a socket address. Problem reported by Philipp Stephani in: http://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00314.html This fix is based on a patch by Philipp in: http://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00357.html
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/process.c b/src/process.c
index 0edd092ef66..4a286391f88 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3420,16 +3420,32 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos,
#ifdef HAVE_GETSOCKNAME
if (p->port == 0)
{
- struct sockaddr_in sa1;
+ struct sockaddr_storage sa1;
socklen_t len1 = sizeof (sa1);
if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
{
- Lisp_Object service;
- service = make_number (ntohs (sa1.sin_port));
- contact = Fplist_put (contact, QCservice, service);
/* Save the port number so that we can stash it in
the process object later. */
- ((struct sockaddr_in *)sa)->sin_port = sa1.sin_port;
+ int port = -1;
+ switch (family)
+ {
+ case AF_INET:
+ ((struct sockaddr_in *) sa)->sin_port
+ = port = ((struct sockaddr_in *) &sa1)->sin_port;
+ break;
+# ifdef AF_INET6
+ case AF_INET6:
+ ((struct sockaddr_in6 *) sa)->sin6_port
+ = port = ((struct sockaddr_in6 *) &sa1)->sin6_port;
+ break;
+# endif
+ }
+
+ if (0 <= port)
+ {
+ Lisp_Object service = make_number (ntohs (port));
+ contact = Fplist_put (contact, QCservice, service);
+ }
}
}
#endif
@@ -3535,7 +3551,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos,
#ifdef HAVE_GETSOCKNAME
if (!p->is_server)
{
- struct sockaddr_in sa1;
+ struct sockaddr_storage sa1;
socklen_t len1 = sizeof (sa1);
if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
contact = Fplist_put (contact, QClocal,