alpine 3.6
format weakness #67

4

Weakness Breakdown


Definition:

A format string exploit occurs when the data of an input string is evaluated as a command by the program. This class of attacks is very similar to buffer overflows since an attacker could execute code, read the stack or cause new behaviors that compromise security. Learn more about format string attacks on OWASP attack index.

Warning code(s):

If format strings can be influenced by an attacker, they can be exploited.

File Name:

heirloom-mailx/src/mailx-12.4/quit.c

Context:

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

 		c = getc(ibuf);
		while (c != EOF) {
			putc(c, obuf);
			if (ferror(obuf))
				break;
			c = getc(ibuf);
		}
		Fclose(ibuf);
		fflush(obuf);
	}
	trunc(obuf);
	if (ferror(obuf)) {
		perror(mbox);
		Fclose(obuf);
		return STOP;
	}
	if (Fclose(obuf) != 0) {
		if (prot != PROTO_IMAP)
			perror(mbox);
		return STOP;
	}
	if (mcount == 1)
		printf(catgets(catd, CATSET, 164, "Saved 1 message in mbox\n"));
	else
		printf(catgets(catd, CATSET, 165,
				"Saved %d messages in mbox\n"), mcount);
	return OKAY;
}

/*
 * Terminate an editing session by attempting to write out the user's
 * file from the temporary.  Save any new stuff appended to the file.
 */
static void 
edstop(void)
{
	int gotcha, c;
	struct message *mp;
	FILE *obuf, *ibuf = NULL, *readstat = NULL;
	struct stat statb;

	if (mb.mb_perm == 0)
		return;
	holdsigs();
	if (Tflag != NULL) {
		if ((readstat = Zopen(Tflag, "w", NULL)) == NULL)
			Tflag = NULL;
	}
	for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MNEW) { 

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.