alpine 3.6
format weakness #60

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.

 			p++;
			if (send(mp, obuf, NULL, NULL, SEND_MBOX, NULL) < 0) {
				perror(mailname);
				fseek(obuf, 0L, SEEK_SET);
				return(-1);
			}
		}
#ifdef APPEND
	if (res != NULL)
		while ((c = getc(res)) != EOF)
			putc(c, obuf);
#endif
	fflush(obuf);
	trunc(obuf);
	if (ferror(obuf)) {
		perror(mailname);
		fseek(obuf, 0L, SEEK_SET);
		return(-1);
	}
	if (res != NULL)
		Fclose(res);
	fseek(obuf, 0L, SEEK_SET);
	alter(mailname);
	if (p == 1)
		printf(catgets(catd, CATSET, 155,
				"Held 1 message in %s\n"), mailname);
	else
		printf(catgets(catd, CATSET, 156,
				"Held %d messages in %s\n"), p, mailname);
	return(0);
}

/*
 * Save all of the undetermined messages at the top of "mbox"
 * Save all untouched messages back in the system mailbox.
 * Remove the system mailbox, if none saved there.
 */
void 
quit(void)
{
	int p, modify, anystat;
	FILE *fbuf, *rbuf, *readstat = NULL, *abuf;
	struct message *mp;
	int c;
	char *tempResid;
	struct stat minfo;

	/*
	 * If we are read only, we can't do anything,
	 * so just return quickly. IMAP can set some 

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.