diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-02 20:08:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-02 20:08:22 +0100 |
commit | da1f872c50c0341c80c4897ccd2a8abcd9ea57e0 (patch) | |
tree | 6c55c27fc842946bb6a510656f36b87047a6b50b | |
parent | 25f1bddc7278b2537e5c2a04b1a59609f0e411ec (diff) | |
download | rspamd-da1f872c50c0341c80c4897ccd2a8abcd9ea57e0.tar.gz rspamd-da1f872c50c0341c80c4897ccd2a8abcd9ea57e0.zip |
[Minor] Handle unexpected cases
-rw-r--r-- | src/libutil/cxx/locked_file.cxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libutil/cxx/locked_file.cxx b/src/libutil/cxx/locked_file.cxx index f392d9b4a..13406c6cf 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<raii_l #ifdef O_CLOEXEC oflags |= O_CLOEXEC; #endif + + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags); if (fd == -1) { @@ -67,6 +72,11 @@ auto raii_locked_file::create(const char *fname, int flags, int perms) -> 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) { |