From 3293ad0fbcf58bb970868fb48b2329253c404282 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 7 May 2020 09:30:02 +0200 Subject: [PATCH] ifcfg-rh: check return value of fdopen() Reported by coverity: >>> CID 210222: Null pointer dereferences (NULL_RETURNS) >>> Dereferencing a pointer that might be "NULL" "f" when calling "fseek". Fixes: ac5206aa9c5a ('2007-11-21') (cherry picked from commit 581aa981c27d4bde17eb8772fe92697f586a6ed6) (cherry picked from commit bb40de0ca02e4f41e17d3fdccd0df87c79182bdd) (cherry picked from commit cde95a3c755cc350ea0b9d24f35f88b2b2aad067) --- src/settings/plugins/ifcfg-rh/shvar.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index d4bc71f3f5..f00b5e2361 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -1420,6 +1420,13 @@ svWriteFile (shvarFile *s, int mode, GError **error) return FALSE; } f = fdopen (tmpfd, "w"); + if (!f) { + errsv = errno; + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv), + "Internal error writing file '%s': %s", + s->fileName, nm_strerror_native (errsv)); + return FALSE; + } fseek (f, 0, SEEK_SET); c_list_for_each (current, &s->lst_head) { const shvarLine *line = c_list_entry (current, shvarLine, lst);