From 5d8791a9d03645d3611b4d1781007a98335c06bb Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Wed, 4 Dec 2013 17:08:23 +0800 Subject: [PATCH] Ensure DBusError is set if _dbus_read_nonce() fail In _dbus_send_nonce() which call in _dbus_read_nonce() and assert on an error is set if _dbus_read_nonce() fail. However, in _dbus_read_nonce(), it may fail on fopen() and left error is unset. This will crash us if assertions hasn't been disabled. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=72298 --- dbus/dbus-nonce.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dbus/dbus-nonce.c b/dbus/dbus-nonce.c index ef037ef..720f11f 100644 --- a/dbus/dbus-nonce.c +++ b/dbus/dbus-nonce.c @@ -112,13 +112,11 @@ _dbus_read_nonce (const DBusString *fname, DBusString *nonce, DBusError* error) fp = fopen (_dbus_string_get_const_data (fname), "rb"); - if (!fp) - return FALSE; - nread = fread (buffer, 1, sizeof buffer - 1, fp); - fclose (fp); - if (!nread) + if (!fp || !(nread = fread (buffer, 1, sizeof buffer - 1, fp))) { dbus_set_error (error, DBUS_ERROR_FILE_NOT_FOUND, "Could not read nonce from file %s", _dbus_string_get_const_data (fname)); + if (fp) + fclose (fp); return FALSE; } -- 1.7.9.5