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.
If format strings can be influenced by an attacker, they can be exploited.
heirloom-mailx/src/mailx-12.4/openssl.c
The highlighted line of code below is the trigger point of this particular Alpine 3.6 format weakness.
{
char *certvar, *keyvar, *cert, *key;
certvar = ac_alloc(strlen(uhp) + 10);
strcpy(certvar, "ssl-cert-");
strcpy(&certvar[9], uhp);
if ((cert = value(certvar)) != NULL ||
(cert = value("ssl-cert")) != NULL) {
cert = expand(cert);
if (SSL_CTX_use_certificate_chain_file(sp->s_ctx, cert) == 1) {
keyvar = ac_alloc(strlen(uhp) + 9);
strcpy(keyvar, "ssl-key-");
if ((key = value(keyvar)) == NULL &&
(key = value("ssl-key")) == NULL)
key = cert;
else
key = expand(key);
if (SSL_CTX_use_PrivateKey_file(sp->s_ctx, key,
SSL_FILETYPE_PEM) != 1)
fprintf(stderr, catgets(catd, CATSET, 238,
"cannot load private key from file %s\n"),
key);
ac_free(keyvar);
} else
fprintf(stderr, catgets(catd, CATSET, 239,
"cannot load certificate from file %s\n"),
cert);
}
ac_free(certvar);
}
static enum okay
ssl_check_host(const char *server, struct sock *sp)
{
X509 *cert;
X509_NAME *subj;
char data[256];
/*GENERAL_NAMES*/STACK *gens;
GENERAL_NAME *gen;
int i;
if ((cert = SSL_get_peer_certificate(sp->s_ssl)) == NULL) {
fprintf(stderr, catgets(catd, CATSET, 248,
"no certificate from \"%s\"\n"), server);
return STOP;
}
gens = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL);
if (gens != NULL) {
for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
gen = sk_GENERAL_NAME_value(gens, i);