qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1632092 - in /qpid/proton/trunk/proton-c/src: posix/io.c windows/io.c
Date Wed, 15 Oct 2014 15:31:20 GMT
Author: rhs
Date: Wed Oct 15 15:31:20 2014
New Revision: 1632092

URL: http://svn.apache.org/r1632092
Log:
PROTON-712: check getprotobyname for NULL return value (patch from Sahir Hoda)

Modified:
    qpid/proton/trunk/proton-c/src/posix/io.c
    qpid/proton/trunk/proton-c/src/windows/io.c

Modified: qpid/proton/trunk/proton-c/src/posix/io.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/posix/io.c?rev=1632092&r1=1632091&r2=1632092&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/posix/io.c (original)
+++ qpid/proton/trunk/proton-c/src/posix/io.c Wed Oct 15 15:31:20 2014
@@ -228,7 +228,11 @@ ssize_t pn_send(pn_io_t *io, pn_socket_t
 }
 
 static inline int pn_create_socket(int af) {
-  return socket(af, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  struct protoent * pe_tcp = getprotobyname("tcp");
+  if (pe_tcp == NULL) {
+    return -1;
+  }
+  return socket(af, SOCK_STREAM, pe_tcp->p_proto);
 }
 #elif defined(SO_NOSIGPIPE)
 ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size) {
@@ -238,7 +242,13 @@ ssize_t pn_send(pn_io_t *io, pn_socket_t
 }
 
 static inline int pn_create_socket(int af) {
-  int sock = socket(af, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  struct protoent * pe_tcp;
+  int sock;
+  pe_tcp = getprotobyname("tcp");
+  if (pe_tcp == NULL) {
+    return -1;
+  }
+  sock = socket(af, SOCK_STREAM, pe_tcp->p_proto);
   if (sock == -1) return sock;
 
   int optval = 1;

Modified: qpid/proton/trunk/proton-c/src/windows/io.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/windows/io.c?rev=1632092&r1=1632091&r2=1632092&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/windows/io.c (original)
+++ qpid/proton/trunk/proton-c/src/windows/io.c Wed Oct 15 15:31:20 2014
@@ -302,7 +302,11 @@ pn_socket_t pn_accept(pn_io_t *io, pn_so
 }
 
 static inline pn_socket_t pni_create_socket() {
-  return socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  struct protoent * pe_tcp = getprotobyname("tcp");
+  if (pe_tcp == NULL) {
+    return -1;
+  }
+  return socket(AF_INET, SOCK_STREAM, pe_tcp->p_proto);
 }
 
 ssize_t pn_send(pn_io_t *io, pn_socket_t sockfd, const void *buf, size_t len) {
@@ -375,8 +379,13 @@ static void configure_pipe_socket(pn_io_
 
 static int pni_socket_pair (pn_io_t *io, SOCKET sv[2]) {
   // no socketpair on windows.  provide pipe() semantics using sockets
+  struct protoent * pe_tcp = getprotobyname("tcp");
+  if (pe_tcp == NULL) {
+    perror("getprotobyname");
+    return -1;
+  }
 
-  SOCKET sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  SOCKET sock = socket(AF_INET, SOCK_STREAM, pe_tcp->p_proto);
   if (sock == INVALID_SOCKET) {
     perror("socket");
     return -1;
@@ -407,7 +416,7 @@ static int pni_socket_pair (pn_io_t *io,
     return -1;
   }
 
-  if ((sv[1] = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto)) == INVALID_SOCKET)
{
+  if ((sv[1] = socket(AF_INET, SOCK_STREAM, pe_tcp->p_proto)) == INVALID_SOCKET) {
     perror("sock1");
     closesocket(sock);
     return -1;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message