From 474b3b1cc80a7c686d4a5fecc6836ec48c7c01d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bodo=20M=C3=B6ller?= Date: Mon, 4 Aug 2008 22:10:38 +0000 Subject: [PATCH] Fix error codes for memory-saving patch. Also, get rid of compile-time switch OPENSSL_NO_RELEASE_BUFFERS because it was rather pointless (the new behavior has to be explicitly requested by setting SSL_MODE_RELEASE_BUFFERS anyway). --- ssl/s3_both.c | 6 +++--- ssl/s3_pkt.c | 14 ++++---------- ssl/ssl.h | 5 +++-- ssl/ssl_err.c | 5 +++-- ssl/ssl_lib.c | 6 +++--- ssl/ssl_locl.h | 2 +- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ssl/s3_both.c b/ssl/s3_both.c index 88bed0fa6b..06e761b4b2 100644 --- a/ssl/s3_both.c +++ b/ssl/s3_both.c @@ -591,7 +591,7 @@ int ssl_verify_alarm_type(long type) return(al); } -#if !defined(OPENSSL_NO_BUF_FREELISTS) && !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS /* On some platforms, malloc() performance is bad enough that you can't just * free() and malloc() buffers all the time, so we need to use freelists from * unused buffers. Currently, each freelist holds memory chunks of only a @@ -698,7 +698,7 @@ int ssl3_setup_read_buffer(SSL *s) return 1; err: - SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); + SSLerr(SSL_F_SSL3_SETUP_READ_BUFFER,ERR_R_MALLOC_FAILURE); return 0; } @@ -733,7 +733,7 @@ int ssl3_setup_write_buffer(SSL *s) return 1; err: - SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); + SSLerr(SSL_F_SSL3_SETUP_WRITE_BUFFER,ERR_R_MALLOC_FAILURE); return 0; } diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c index b4a1629853..07dd4b23d5 100644 --- a/ssl/s3_pkt.c +++ b/ssl/s3_pkt.c @@ -238,11 +238,9 @@ int ssl3_read_n(SSL *s, int n, int max, int extend) if (i <= 0) { rb->left = left; -#ifndef OPENSSL_NO_RELEASE_BUFFERS - if (len+left == 0 && - (s->mode & SSL_MODE_RELEASE_BUFFERS)) - ssl3_release_read_buffer(s); -#endif + if (s->mode & SSL_MODE_RELEASE_BUFFERS) + if (len+left == 0) + ssl3_release_read_buffer(s); return(i); } left+=i; @@ -825,10 +823,8 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, { wb->left=0; wb->offset+=i; -#ifndef OPENSSL_NO_RELEASE_BUFFERS if (s->mode & SSL_MODE_RELEASE_BUFFERS) ssl3_release_write_buffer(s); -#endif s->rwstate=SSL_NOTHING; return(s->s3->wpend_ret); } @@ -983,10 +979,8 @@ start: { s->rstate=SSL_ST_READ_HEADER; rr->off=0; -#ifndef OPENSSL_NO_RELEASE_BUFFERS - if ((s->mode & SSL_MODE_RELEASE_BUFFERS)) + if (s->mode & SSL_MODE_RELEASE_BUFFERS) ssl3_release_read_buffer(s); -#endif } } return(n); diff --git a/ssl/ssl.h b/ssl/ssl.h index da105e940c..af6702030b 100644 --- a/ssl/ssl.h +++ b/ssl/ssl.h @@ -840,7 +840,7 @@ struct ssl_ctx_st unsigned char *psk, unsigned int max_psk_len); #endif -#if !defined(OPENSSL_NO_BUF_FREELISTS) || !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS #define SSL_MAX_BUF_FREELIST_LEN_DEFAULT 32 unsigned int freelist_max_len; struct ssl3_buf_freelist_st *wbuf_freelist; @@ -1851,8 +1851,9 @@ void ERR_load_SSL_strings(void); #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 #define SSL_F_SSL3_SEND_SERVER_HELLO 242 #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 -#define SSL_F_SSL3_SETUP_BUFFERS 156 #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 +#define SSL_F_SSL3_SETUP_READ_BUFFER 156 +#define SSL_F_SSL3_SETUP_WRITE_BUFFER 291 #define SSL_F_SSL3_WRITE_BYTES 158 #define SSL_F_SSL3_WRITE_PENDING 159 #define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 277 diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c index 21fcd3fd44..a93cc4c674 100644 --- a/ssl/ssl_err.c +++ b/ssl/ssl_err.c @@ -1,6 +1,6 @@ /* ssl/ssl_err.c */ /* ==================================================================== - * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. + * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -167,8 +167,9 @@ static ERR_STRING_DATA SSL_str_functs[]= {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_CERTIFICATE), "SSL3_SEND_SERVER_CERTIFICATE"}, {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_HELLO), "SSL3_SEND_SERVER_HELLO"}, {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, -{ERR_FUNC(SSL_F_SSL3_SETUP_BUFFERS), "SSL3_SETUP_BUFFERS"}, {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"}, +{ERR_FUNC(SSL_F_SSL3_SETUP_READ_BUFFER), "SSL3_SETUP_READ_BUFFER"}, +{ERR_FUNC(SSL_F_SSL3_SETUP_WRITE_BUFFER), "SSL3_SETUP_WRITE_BUFFER"}, {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"}, {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"}, {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT), "SSL_ADD_CLIENTHELLO_TLSEXT"}, diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 736423fd15..203bce661a 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -1581,7 +1581,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) ret->psk_client_callback=NULL; ret->psk_server_callback=NULL; #endif -#if !defined(OPENSSL_NO_BUF_FREELISTS) && !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS ret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT; ret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST)); if (!ret->rbuf_freelist) @@ -1633,7 +1633,7 @@ static void SSL_COMP_free(SSL_COMP *comp) { OPENSSL_free(comp); } #endif -#if !defined(OPENSSL_NO_BUF_FREELISTS) && !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS static void ssl_buf_freelist_free(SSL3_BUF_FREELIST *list) { @@ -1714,7 +1714,7 @@ void SSL_CTX_free(SSL_CTX *a) ENGINE_finish(a->client_cert_engine); #endif -#if !defined(OPENSSL_NO_BUF_FREELISTS) && !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS if (a->wbuf_freelist) ssl_buf_freelist_free(a->wbuf_freelist); if (a->rbuf_freelist) diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index e3cb05e2f6..fc77fd0bde 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -561,7 +561,7 @@ typedef struct ssl3_comp_st COMP_METHOD *method; /* The method :-) */ } SSL3_COMP; -#if !defined(OPENSSL_NO_BUF_FREELISTS) && !defined(OPENSSL_NO_RELEASE_BUFFERS) +#ifndef OPENSSL_NO_BUF_FREELISTS typedef struct ssl3_buf_freelist_st { size_t chunklen;