alpine 3.6
access weakness #185

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:

dateutils/src/dateutils-0.4.1/build-aux/yuck.c

Context:

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

 	}
	return;
}

static int
mktempp(char *restrict tmpl[static 1U], int prefixlen)
{
	static mode_t umsk;
	char *bp = *tmpl + prefixlen;
	char *const ep = *tmpl + strlen(*tmpl);
	mode_t m;
	int fd;

	if (UNLIKELY(!umsk)) {
		umsk = umask(0022);
	}
	if (ep[-6] != 'X' || ep[-5] != 'X' || ep[-4] != 'X' ||
	    ep[-3] != 'X' || ep[-2] != 'X' || ep[-1] != 'X') {
		if ((fd = open(bp, O_RDWR | O_CREAT | O_EXCL, 0666)) < 0 &&
		    (bp -= prefixlen,
		     fd = open(bp, O_RDWR | O_CREAT | O_EXCL, 0666)) < 0) {
			/* fuck that then */
			return -1;
		}
	} else if (m = umask(S_IXUSR | S_IRWXG | S_IRWXO),
		   UNLIKELY((fd = mkstemp(bp), umask(m), fd < 0)) &&
		   UNLIKELY((bp -= prefixlen,
			     /* reset to XXXXXX */
			     memset(ep - 6, 'X', 6U),
			     fd = mkstemp(bp)) < 0)) {
		/* at least we tried */
		return -1;
	}
	/* store result */
	*tmpl = bp;
	return fd;
}

static FILE*
mkftempp(char *restrict tmpl[static 1U], int prefixlen)
{
	int fd;

	if (UNLIKELY((fd = mktempp(tmpl, prefixlen)) < 0)) {
		return NULL;
	}
	return fdopen(fd, "w");
}

# if defined WITH_SCMVER 

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.