From: Joe Orton Date: Fri, 15 Apr 2005 10:51:44 +0000 (+0000) Subject: Fix and prevent some segfaults in ab: X-Git-Tag: 2.1.5~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4800ec9ba7f3cbd02b9b99382c86724944bf5ccf;p=thirdparty%2Fapache%2Fhttpd.git Fix and prevent some segfaults in ab: * support/ab.c (main): Fail if given concurrency level greater than number of requests, to prevent segfaults later. (ssl_print_cert_info): Use the correct buffer size. (ssl_start_connect): SSL_get_peer_cert_chain doesn't bump refcounts, so don't free the cert chain here. (test): Use both calloc parameters (unrelated cleanup). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@161437 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/support/ab.c b/support/ab.c index 03face7d241..a6c03de672e 100644 --- a/support/ab.c +++ b/support/ab.c @@ -545,11 +545,11 @@ static int ssl_print_cert_info(BIO *bio, X509 *x509cert) EVP_PKEY_bits(X509_get_pubkey(x509cert))); dn=X509_get_issuer_name(x509cert); - X509_NAME_oneline(dn, buf, BUFSIZ); + X509_NAME_oneline(dn, buf, sizeof buf); BIO_printf(bio,"The issuer name is %s\n", buf); dn=X509_get_subject_name(x509cert); - X509_NAME_oneline(dn, buf, BUFSIZ); + X509_NAME_oneline(dn, buf, sizeof buf); BIO_printf(bio,"The subject name is %s\n", buf); /* dump the extension list too */ @@ -665,7 +665,6 @@ static void ssl_start_connect(struct connection * c) x509cert = (X509 *)sk_X509_value(sk,i); #endif ssl_print_cert_info(bio_out,x509cert); - X509_free(x509cert); } } @@ -1562,9 +1561,9 @@ static void test(void) now = apr_time_now(); - con = calloc(concurrency * sizeof(struct connection), 1); + con = calloc(concurrency, sizeof(struct connection)); - stats = calloc(requests * sizeof(struct data), 1); + stats = calloc(requests, sizeof(struct data)); if ((status = apr_pollset_create(&readbits, concurrency, cntxt, 0)) != APR_SUCCESS) { apr_err("apr_pollset_create failed", status); @@ -2174,6 +2173,12 @@ int main(int argc, const char * const argv[]) usage(argv[0]); } + if (concurrency > requests) { + fprintf(stderr, "%s: Cannot use concurrency level greater than " + "total number of requests\n", argv[0]); + usage(argv[0]); + } + if ((heartbeatres) && (requests > 150)) { heartbeatres = requests / 10; /* Print line every 10% of requests */ if (heartbeatres < 100)