]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Handle unexpected cases
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 2 May 2022 19:08:22 +0000 (20:08 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 2 May 2022 19:08:22 +0000 (20:08 +0100)
src/libutil/cxx/locked_file.cxx

index f392d9b4a581f4416c4a1899702ce7d933790136..13406c6cfc4c72cdfd52dcb2f533f6cdd2de2f99 100644 (file)
@@ -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) {