summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-02 20:15:31 +0200
committerThomas Haller <thaller@redhat.com>2017-06-02 20:21:11 +0200
commitfb9411ff76c3f3ef57cd19eed06cf21b89db2e95 (patch)
tree25c9fbc33bcf56803c4d0f2d3621b8b05a573386
parentcd8f3cf09f7d4e869ca4930e8219bedab342ec6f (diff)
downloadNetworkManager-fb9411ff76c3f3ef57cd19eed06cf21b89db2e95.tar.gz
settings: refactor nm_settings_connection_read_and_fill_timestamp()
Coverity complains about not checking the return value: src/settings/nm-settings-connection.c:2329: check_return: Calling "g_key_file_load_from_file" without checking return value (as is done elsewhere 6 out of 7 times). While at it, refactor the code and check whether the timestamp is valid. (cherry picked from commit 238efbbb12d32b4d4b7827509b4f21af9d159617)
-rw-r--r--src/settings/nm-settings-connection.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index 0cb2920c58..bc6dcfce13 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -2316,33 +2316,35 @@ void
nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self)
{
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
+ gs_unref_keyfile GKeyFile *timestamps_file = NULL;
+ gs_free_error GError *error = NULL;
+ gs_free char *tmp_str = NULL;
const char *connection_uuid;
- guint64 timestamp = 0;
- GKeyFile *timestamps_file;
- GError *err = NULL;
- char *tmp_str;
+ gint64 timestamp;
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
- /* Get timestamp from database file */
timestamps_file = g_key_file_new ();
- g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, NULL);
+ if (!g_key_file_load_from_file (timestamps_file, SETTINGS_TIMESTAMPS_FILE, G_KEY_FILE_KEEP_COMMENTS, &error)) {
+ _LOGD ("failed to read connection timestamp: %s", error->message);
+ return;
+ }
+
connection_uuid = nm_settings_connection_get_uuid (self);
- tmp_str = g_key_file_get_value (timestamps_file, "timestamps", connection_uuid, &err);
- if (tmp_str) {
- timestamp = g_ascii_strtoull (tmp_str, NULL, 10);
- g_free (tmp_str);
+ tmp_str = g_key_file_get_value (timestamps_file, "timestamps", connection_uuid, &error);
+ if (!tmp_str) {
+ _LOGD ("failed to read connection timestamp: %s", error->message);
+ return;
}
- /* Update connection's timestamp */
- if (!err) {
- priv->timestamp = timestamp;
- priv->timestamp_set = TRUE;
- } else {
- _LOGD ("failed to read connection timestamp: %s", err->message);
- g_clear_error (&err);
+ timestamp = _nm_utils_ascii_str_to_int64 (tmp_str, 10, 0, G_MAXINT64, -1);
+ if (timestamp < 0) {
+ _LOGD ("failed to read connection timestamp: %s", "invalid number");
+ return;
}
- g_key_file_free (timestamps_file);
+
+ priv->timestamp = timestamp;
+ priv->timestamp_set = TRUE;
}
/**