From: Vsevolod Stakhov Date: Mon, 2 May 2022 19:08:22 +0000 (+0100) Subject: [Minor] Handle unexpected cases X-Git-Tag: 3.3~284 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da1f872c50c0341c80c4897ccd2a8abcd9ea57e0;p=thirdparty%2Frspamd.git [Minor] Handle unexpected cases --- diff --git a/src/libutil/cxx/locked_file.cxx b/src/libutil/cxx/locked_file.cxx index f392d9b4a5..13406c6cfc 100644 --- a/src/libutil/cxx/locked_file.cxx +++ b/src/libutil/cxx/locked_file.cxx @@ -30,6 +30,11 @@ auto raii_locked_file::open(const char *fname, int flags) -> tl::expected tl::ex #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) { @@ -93,6 +103,10 @@ auto raii_locked_file::create_temp(const char *fname, int flags, int perms) -> t #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) {