commit da1f872: [Minor] Handle unexpected cases
Vsevolod Stakhov
vsevolod at rspamd.com
Mon May 2 19:21:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-05-02 20:08:22 +0100
URL: https://github.com/rspamd/rspamd/commit/da1f872c50c0341c80c4897ccd2a8abcd9ea57e0
[Minor] Handle unexpected cases
---
src/libutil/cxx/locked_file.cxx | 14 ++++++++++++++
1 file changed, 14 insertions(+)
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) {
More information about the Commits
mailing list