From bb40de0ca02e4f41e17d3fdccd0df87c79182bdd 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) --- 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 f2a1dd7875..cd63661d9a 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -1492,6 +1492,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);