getprotobyname() may return NULL, causing segfaults in this function.
authorPhilipp Marek <philipp@marek.priv.at>
Sat, 22 Feb 2014 10:00:53 +0000 (11:00 +0100)
committerPhilipp Marek <philipp@marek.priv.at>
Sat, 22 Feb 2014 10:00:53 +0000 (11:00 +0100)
contrib/sockets/sockets.lisp

index fa05413..9c360d5 100755 (executable)
@@ -517,9 +517,15 @@ safe_buffer_pointer(cl_object x, cl_index size)
 (defun get-protocol-by-name (string-or-symbol)
   "Calls getprotobyname"
   (let ((string (string string-or-symbol)))
-    (c-inline (string) (:cstring) :int
-             "getprotobyname(#0)->p_proto"
-             :one-liner t)))
+      (c-inline (string) (:cstring) :int
+                "{
+                 struct protoent *pe;
+
+                 pe = getprotobyname(#0);
+                 @(return 0) = pe ? pe->p_proto : -1;
+                 }
+               ")))
+
 
 (defun make-inet-address (dotted-quads)
   "Return a vector of octets given a string DOTTED-QUADS in the format