alpine 3.6
format weakness #5


Weakness Breakdown


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, and note that sprintf variations do not always 0-terminate.

File Name:



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

 int gen_transact(int sock, fmt, va_alist)
int sock;		/** socket to which server is connected */
const char *fmt;	/** printf-style format */
/** assemble command in printf(3) style, send to server, fetch a response */
    int ok;
    char buf [MSGBUFSIZE+1];
    va_list ap;
    int oldphase = phase;	/* we don't have to be re-entrant */

    phase = SERVER_WAIT;

    if (protocol->tagged && !suppress_tags)
	snprintf(buf, sizeof(buf) - 2, "%s ", GENSYM);
	buf[0] = '\0';

#if defined(HAVE_STDARG_H)
    va_start(ap, fmt) ;
    vsnprintf(buf + strlen(buf), sizeof(buf)-2-strlen(buf), fmt, ap);

    snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "\r\n");
    ok = SockWrite(sock, buf, strlen(buf));
    if (ok == -1 || (size_t)ok != strlen(buf)) {
	/* short write, bail out */
	return PS_SOCKET;

    if (outlevel >= O_MONITOR)
	buf[strlen(buf)-2] = '\0';
	report(stdout, "%s> %s\n", protocol->name, buf);

    /* we presume this does its own response echoing */
    ok = (protocol->parse_response)(sock, buf);

    phase = oldphase;

/* transact.c ends here */ 

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.