From ab1b0bf0f3611b556627f42e5accb1063acd91cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Mon, 20 May 2019 14:19:01 +0200 Subject: [PATCH 1/3] import: Don't call unlink(NULL) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although `man 3 unlink` doesn't mention what should be the unlink() behaviour when NULL is passed to it, both coverity and clang complains about that. Error: FORWARD_NULL (CWE-476): osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:157: var_compare_op: Comparing "*source_file" to null implies that "*source_file" might be null. osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:181: var_deref_model: Passing null pointer "*source_file" to "unlink", which dereferences it. # 179| g_error_free(err); # 180| if (ret != 0) # 181|-> unlink(*source_file); # 182| # 183| return ret; Error: CLANG_WARNING: osinfo-db-tools-1.5.0/tools/osinfo-db-import.c:181:9: warning: Null pointer passed as an argument to a 'nonnull' parameter # unlink(*source_file); # ^ Signed-off-by: Fabiano FidĂȘncio Reviewed-by: Cole Robinson (cherry picked from commit 07be7309d830419c27ec65c76905d1e23219f480) --- tools/osinfo-db-import.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/osinfo-db-import.c b/tools/osinfo-db-import.c index 920f71b..11e68ae 100644 --- a/tools/osinfo-db-import.c +++ b/tools/osinfo-db-import.c @@ -177,7 +177,7 @@ osinfo_db_import_download_file(GFile *file, g_object_unref(out); if (err != NULL) g_error_free(err); - if (ret != 0) + if (ret != 0 && *source_file != NULL) unlink(*source_file); return ret; -- 2.21.0