summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2019-12-17 15:19:50 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2019-12-18 10:02:48 +0100
commitcfc418f8876a7adab0e23bbd10fe9725c7b60b2e (patch)
treec314b80af0133fc02e341bdec903ad90539f91c8 /src
parent0de4fd6ebc4c3909838087e254a24359e816d0be (diff)
downloadNetworkManager-cfc418f8876a7adab0e23bbd10fe9725c7b60b2e.tar.gz
dhcp: nettools: check return value of g_file_set_contents()
Found by covscan: NetworkManager-1.22.0/src/dhcp/nm-dhcp-nettools.c:945: check_return: Calling "g_file_set_contents" without checking return value (as is done elsewhere 16 out of 20 times). Fixes: 9f8951692822 ('dhcp: nettools: read/write lease files')
Diffstat (limited to 'src')
-rw-r--r--src/dhcp/nm-dhcp-nettools.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 8fd2852b41..2cb7c51b61 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -924,11 +924,12 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
/*****************************************************************************/
static void
-lease_save (NDhcp4ClientLease *lease, const char *lease_file)
+lease_save (NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_file)
{
struct in_addr a_address;
nm_auto_free_gstring GString *new_contents = NULL;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
+ gs_free_error GError *error = NULL;
nm_assert (lease);
nm_assert (lease_file);
@@ -942,10 +943,11 @@ lease_save (NDhcp4ClientLease *lease, const char *lease_file)
g_string_append_printf (new_contents,
"ADDRESS=%s\n", nm_utils_inet4_ntop (a_address.s_addr, sbuf));
- g_file_set_contents (lease_file,
- new_contents->str,
- -1,
- NULL);
+ if (!g_file_set_contents (lease_file,
+ new_contents->str,
+ -1,
+ &error))
+ _LOGW ("error saving lease to %s: %s", lease_file, error->message);
}
static void
@@ -975,7 +977,7 @@ bound4_handle (NMDhcpNettools *self, NDhcp4ClientLease *lease)
}
nm_dhcp_option_add_requests_to_options (options, _nm_dhcp_option_dhcp4_options);
- lease_save (lease, priv->lease_file);
+ lease_save (self, lease, priv->lease_file);
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
NM_DHCP_STATE_BOUND,