alpine 3.6
access weakness #497

1

Weakness Breakdown


Definition:

An access weakness occurs when software does not properly implement permissions that could have unintended consequences if exploited by malicious actors. An example of this weakness is when a default username and password are set by the developer but do not get changed by the system administrator.

Warning code(s):

Ensure that umask is given most restrictive possible setting.

File Name:

dansguardian/src/dansguardian-2.12.0.3/src/BackedStore.cpp

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.6 access weakness.

 		{
			// Would exceed RAM threshold
			if (rambuf.size() + len > disksize)
			{
				// Would also exceed disk threshold
				// - give up
#ifdef DGDEBUG
				std::cout << "BackedStore: data would exceed both RAM and disk thresholds" << std::endl;
#endif
				return false;
			}

#ifdef DGDEBUG
			std::cout << "BackedStore: data would exceed RAM threshold; dumping RAM to disk" << std::endl;
#endif

			// Open temp file, dump current data in there,
			// leave code below this if{} to write current
			// data to the file as well
			std::string filename_str = tempdir + "/__dgbsXXXXXX";
			filename = const_cast<char*>(filename_str.c_str());
#ifdef DGDEBUG
			std::cout << "BackedStore: filename template: " << filename << std::endl;
#endif
			umask(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
			if ((fd = mkstemp(filename)) < 0)
			{
				std::ostringstream ss;
				ss << "BackedStore could not create temp file: " << strerror(errno);
				free(filename);
				throw std::runtime_error(ss.str().c_str());
			}
#ifdef DGDEBUG
			std::cout << "BackedStore: filename: " << filename << std::endl;
#endif
			free(filename);

			size_t bytes_written = 0;
			ssize_t rc = 0;
			do
			{
				rc = write(fd, &(rambuf.front()) + bytes_written, rambuf.size() - bytes_written);
				if (rc > 0)
					bytes_written += rc;
			}
			while (bytes_written < rambuf.size() && (rc > 0 || errno == EINTR));
			if (rc < 0 && errno != EINTR)
			{
				std::ostringstream ss;
				ss << "BackedStore could not dump RAM buffer to temp file: " << strerror(errno); 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.