[libsoup] SoupSocket: local, remote address are undefined if unconnected
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] SoupSocket: local, remote address are undefined if unconnected
- Date: Mon, 6 Aug 2012 14:34:11 +0000 (UTC)
commit f75304e6d16f53b544a08776031921bef9535100
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Thu Mar 29 19:17:02 2012 +0100
SoupSocket: local, remote address are undefined if unconnected
Warn and return NULL deterministically, rather than warning and returning
uninitialized stack garbage, but document it as "undefined"; these
methods were never meant to be valid in this situation, apparently.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=673083
libsoup/soup-socket.c | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index 5a88907..4369ff3 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -1280,6 +1280,9 @@ soup_socket_is_connected (SoupSocket *sock)
*
* Returns the #SoupAddress corresponding to the local end of @sock.
*
+ * Calling this method on an unconnected socket is considered to be
+ * an error, and produces undefined results.
+ *
* Return value: (transfer none): the #SoupAddress
**/
SoupAddress *
@@ -1295,13 +1298,25 @@ soup_socket_get_local_address (SoupSocket *sock)
GSocketAddress *addr;
struct sockaddr_storage sa;
gssize sa_len;
+ GError *error = NULL;
+
+ if (priv->gsock == NULL) {
+ g_warning ("%s: socket not connected", G_STRLOC);
+ goto unlock;
+ }
- addr = g_socket_get_local_address (priv->gsock, NULL);
+ addr = g_socket_get_local_address (priv->gsock, &error);
+ if (addr == NULL) {
+ g_warning ("%s: %s", G_STRLOC, error->message);
+ g_error_free (error);
+ goto unlock;
+ }
sa_len = g_socket_address_get_native_size (addr);
g_socket_address_to_native (addr, &sa, sa_len, NULL);
priv->local_addr = soup_address_new_from_sockaddr ((struct sockaddr *)&sa, sa_len);
g_object_unref (addr);
}
+unlock:
g_mutex_unlock (&priv->addrlock);
return priv->local_addr;
@@ -1313,6 +1328,9 @@ soup_socket_get_local_address (SoupSocket *sock)
*
* Returns the #SoupAddress corresponding to the remote end of @sock.
*
+ * Calling this method on an unconnected socket is considered to be
+ * an error, and produces undefined results.
+ *
* Return value: (transfer none): the #SoupAddress
**/
SoupAddress *
@@ -1328,13 +1346,25 @@ soup_socket_get_remote_address (SoupSocket *sock)
GSocketAddress *addr;
struct sockaddr_storage sa;
gssize sa_len;
+ GError *error = NULL;
+
+ if (priv->gsock == NULL) {
+ g_warning ("%s: socket not connected", G_STRLOC);
+ goto unlock;
+ }
- addr = g_socket_get_remote_address (priv->gsock, NULL);
+ addr = g_socket_get_remote_address (priv->gsock, &error);
+ if (addr == NULL) {
+ g_warning ("%s: %s", G_STRLOC, error->message);
+ g_error_free (error);
+ goto unlock;
+ }
sa_len = g_socket_address_get_native_size (addr);
g_socket_address_to_native (addr, &sa, sa_len, NULL);
priv->remote_addr = soup_address_new_from_sockaddr ((struct sockaddr *)&sa, sa_len);
g_object_unref (addr);
}
+unlock:
g_mutex_unlock (&priv->addrlock);
return priv->remote_addr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]