mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 10:48:12 +02:00
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 238efbbb12)
This commit is contained in:
parent
cd8f3cf09f
commit
fb9411ff76
1 changed files with 21 additions and 19 deletions
|
|
@ -2316,33 +2316,35 @@ void
|
||||||
nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self)
|
nm_settings_connection_read_and_fill_timestamp (NMSettingsConnection *self)
|
||||||
{
|
{
|
||||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (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;
|
const char *connection_uuid;
|
||||||
guint64 timestamp = 0;
|
gint64 timestamp;
|
||||||
GKeyFile *timestamps_file;
|
|
||||||
GError *err = NULL;
|
|
||||||
char *tmp_str;
|
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
|
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (self));
|
||||||
|
|
||||||
/* Get timestamp from database file */
|
|
||||||
timestamps_file = g_key_file_new ();
|
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)) {
|
||||||
connection_uuid = nm_settings_connection_get_uuid (self);
|
_LOGD ("failed to read connection timestamp: %s", error->message);
|
||||||
tmp_str = g_key_file_get_value (timestamps_file, "timestamps", connection_uuid, &err);
|
return;
|
||||||
if (tmp_str) {
|
|
||||||
timestamp = g_ascii_strtoull (tmp_str, NULL, 10);
|
|
||||||
g_free (tmp_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update connection's timestamp */
|
connection_uuid = nm_settings_connection_get_uuid (self);
|
||||||
if (!err) {
|
tmp_str = g_key_file_get_value (timestamps_file, "timestamps", connection_uuid, &error);
|
||||||
priv->timestamp = timestamp;
|
if (!tmp_str) {
|
||||||
priv->timestamp_set = TRUE;
|
_LOGD ("failed to read connection timestamp: %s", error->message);
|
||||||
} else {
|
return;
|
||||||
_LOGD ("failed to read connection timestamp: %s", err->message);
|
|
||||||
g_clear_error (&err);
|
|
||||||
}
|
}
|
||||||
g_key_file_free (timestamps_file);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->timestamp = timestamp;
|
||||||
|
priv->timestamp_set = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue