diff options
author | Simon McVittie <smcv@collabora.com> | 2017-11-06 19:11:32 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-11-07 11:38:53 +0000 |
commit | 37d5af203c0fc22c9ae746b2ae4781ff648a792f (patch) | |
tree | 46831d7a1ff5fd21739756024fd761a4dc804eb0 /dbus/dbus-nonce.c | |
parent | 6d08f5c04e601f16ef4ee2126a90c924b7e26df0 (diff) | |
download | dbus-37d5af203c0fc22c9ae746b2ae4781ff648a792f.tar.gz |
_dbus_accept_with_noncefile: Don't leak nonce
This was always leaked, both on success and on error.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
Diffstat (limited to 'dbus/dbus-nonce.c')
-rw-r--r-- | dbus/dbus-nonce.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/dbus/dbus-nonce.c b/dbus/dbus-nonce.c index 7f3118cd..eab23f64 100644 --- a/dbus/dbus-nonce.c +++ b/dbus/dbus-nonce.c @@ -165,24 +165,36 @@ _dbus_read_nonce (const DBusString *fname, DBusString *nonce, DBusError* error) DBusSocket _dbus_accept_with_noncefile (DBusSocket listen_fd, const DBusNonceFile *noncefile) { - DBusSocket fd; + DBusSocket fd = _dbus_socket_get_invalid (); DBusString nonce; _dbus_assert (noncefile != NULL); + + /* Make it valid to "free" this even if _dbus_string_init() runs + * out of memory: see comment in do_check_nonce() */ + _dbus_string_init_const (&nonce, ""); + if (!_dbus_string_init (&nonce)) - return _dbus_socket_get_invalid (); + goto out; + //PENDING(kdab): set better errors if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE) - return _dbus_socket_get_invalid (); + goto out; + fd = _dbus_accept (listen_fd); + if (!_dbus_socket_is_valid (fd)) - return fd; + goto out; + if (do_check_nonce(fd, &nonce, NULL) != TRUE) { _dbus_verbose ("nonce check failed. Closing socket.\n"); _dbus_close_socket(fd, NULL); - return _dbus_socket_get_invalid (); + _dbus_socket_invalidate (&fd); + goto out; } +out: + _dbus_string_free (&nonce); return fd; } |