mirror of
https://github.com/openssl/openssl.git
synced 2026-05-07 20:12:39 +00:00
e077455e9e
Since OPENSSL_malloc() and friends report ERR_R_MALLOC_FAILURE, and
at least handle the file name and line number they are called from,
there's no need to report ERR_R_MALLOC_FAILURE where they are called
directly, or when SSLfatal() and RLAYERfatal() is used, the reason
`ERR_R_MALLOC_FAILURE` is changed to `ERR_R_CRYPTO_LIB`.
There were a number of places where `ERR_R_MALLOC_FAILURE` was reported
even though it was a function from a different sub-system that was
called. Those places are changed to report ERR_R_{lib}_LIB, where
{lib} is the name of that sub-system.
Some of them are tricky to get right, as we have a lot of functions
that belong in the ASN1 sub-system, and all the `sk_` calls or from
the CRYPTO sub-system.
Some extra adaptation was necessary where there were custom OPENSSL_malloc()
wrappers, and some bugs are fixed alongside these changes.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19301)
92 lines
2.0 KiB
C
92 lines
2.0 KiB
C
/*
|
|
* Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
* in the file LICENSE in the source distribution or at
|
|
* https://www.openssl.org/source/license.html
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <openssl/objects.h>
|
|
#include <openssl/comp.h>
|
|
#include <openssl/err.h>
|
|
#include "comp_local.h"
|
|
|
|
COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
|
|
{
|
|
COMP_CTX *ret;
|
|
|
|
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
|
|
return NULL;
|
|
ret->meth = meth;
|
|
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
|
|
OPENSSL_free(ret);
|
|
ret = NULL;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx)
|
|
{
|
|
return ctx->meth;
|
|
}
|
|
|
|
int COMP_get_type(const COMP_METHOD *meth)
|
|
{
|
|
return meth->type;
|
|
}
|
|
|
|
const char *COMP_get_name(const COMP_METHOD *meth)
|
|
{
|
|
return meth->name;
|
|
}
|
|
|
|
void COMP_CTX_free(COMP_CTX *ctx)
|
|
{
|
|
if (ctx == NULL)
|
|
return;
|
|
if (ctx->meth->finish != NULL)
|
|
ctx->meth->finish(ctx);
|
|
|
|
OPENSSL_free(ctx);
|
|
}
|
|
|
|
int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
|
unsigned char *in, int ilen)
|
|
{
|
|
int ret;
|
|
if (ctx->meth->compress == NULL) {
|
|
return -1;
|
|
}
|
|
ret = ctx->meth->compress(ctx, out, olen, in, ilen);
|
|
if (ret > 0) {
|
|
ctx->compress_in += ilen;
|
|
ctx->compress_out += ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
|
unsigned char *in, int ilen)
|
|
{
|
|
int ret;
|
|
|
|
if (ctx->meth->expand == NULL) {
|
|
return -1;
|
|
}
|
|
ret = ctx->meth->expand(ctx, out, olen, in, ilen);
|
|
if (ret > 0) {
|
|
ctx->expand_in += ilen;
|
|
ctx->expand_out += ret;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int COMP_CTX_get_type(const COMP_CTX* comp)
|
|
{
|
|
return comp->meth ? comp->meth->type : NID_undef;
|
|
}
|