Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/DiskIO/AIO/AIODiskFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

CBDATA_CLASS_INIT(AIODiskFile);

AIODiskFile::AIODiskFile(char const *aPath, AIODiskIOStrategy *aStrategy) : fd(-1), closed(true), error_(false)
AIODiskFile::AIODiskFile(char const *aPath, AIODiskIOStrategy *aStrategy) :
path(aPath),
strategy(aStrategy)
{
assert (aPath);
path = aPath;
strategy = aStrategy;
debugs(79, 3, "AIODiskFile::AIODiskFile: " << aPath);
assert(!path.isEmpty());
debugs(79, 3, path);
}

AIODiskFile::~AIODiskFile()
Expand All @@ -56,9 +56,9 @@ AIODiskFile::open(int flags, mode_t, RefCount<IORequestor> callback)
{
/* Simulate async calls */
#if _SQUID_WINDOWS_
fd = aio_open(path.termedBuf(), flags);
fd = aio_open(path.c_str(), flags);
#else
fd = file_open(path.termedBuf(), flags);
fd = file_open(path.c_str(), flags);
#endif

ioRequestor = callback;
Expand Down
12 changes: 6 additions & 6 deletions src/DiskIO/AIO/AIODiskFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "cbdata.h"
#include "DiskIO/AIO/async_io.h"
#include "DiskIO/DiskFile.h"
#include "SquidString.h"
#include "sbuf/SBuf.h"

class AIODiskIOStrategy;

Expand Down Expand Up @@ -48,12 +48,12 @@ class AIODiskFile : public DiskFile

private:
void error(bool const &);
int fd;
String path;
AIODiskIOStrategy *strategy;
int fd = -1;
SBuf path;
AIODiskIOStrategy *strategy = nullptr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this data member must be set by the class constructor, then it is best to leave it uninitialized here to avoid implying that some reasonable initial or default value exists:

Suggested change
AIODiskIOStrategy *strategy = nullptr;
AIODiskIOStrategy *strategy;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That practice being requested is a "bad practice".

Reason: The "undefined" value is completely random. Which means it may be a value within the application legitimately allocated memory and thus indistinguishable from a valid allocation when inspected by memory access checkers.

[ Given Squid memory pooling design, the allocation will be from a previously allocated object of the same type, meaning a high chance that the pointed to memory would have the structure of a legitimate (but not valid) strategy object. ]

Solution: Explicitly initialize to a value which is guaranteed to be outside accessible memory ranges. The value nullptr, NULL, or 0 are traditionally used for this.

RefCount<IORequestor> ioRequestor;
bool closed;
bool error_;
bool closed = true;
bool error_ = false;
};

#endif /* HAVE_DISKIO_MODULE_AIO */
Expand Down
Loading