开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (27)
标签 (371)
master
feature/dtls-1.3
openssl-3.0
openssl-3.1
openssl-3.2
openssl-3.3
feature/quic-server
gost-engines-dir
OpenSSL_1_1_1-stable
OpenSSL_1_0_2-stable
OpenSSL_1_1_0-stable
OpenSSL-fips-2_0-stable
OpenSSL-fips-2_0-dev
tls1.3-draft-18
tls1.3-draft-19
OpenSSL_1_0_1-stable
OpenSSL_1_0_0-stable
OpenSSL_0_9_8-stable
OpenSSL-fips-1_2-stable
OpenSSL-fips-0_9_8-stable
openssl-3.0.13
openssl-3.1.5
openssl-3.2.1
openssl-3.2.0
openssl-3.2.0-beta1
openssl-3.0.12
openssl-3.1.4
openssl-3.2.0-alpha2
openssl-3.0.11
openssl-3.1.3
OpenSSL_1_1_1w
openssl-3.2.0-alpha1
OpenSSL_1_1_1v
openssl-3.0.10
openssl-3.1.2
OpenSSL_1_1_1u
openssl-3.0.9
openssl-3.1.1
openssl-3.1.0
openssl-3.0.8
master
分支 (27)
标签 (371)
master
feature/dtls-1.3
openssl-3.0
openssl-3.1
openssl-3.2
openssl-3.3
feature/quic-server
gost-engines-dir
OpenSSL_1_1_1-stable
OpenSSL_1_0_2-stable
OpenSSL_1_1_0-stable
OpenSSL-fips-2_0-stable
OpenSSL-fips-2_0-dev
tls1.3-draft-18
tls1.3-draft-19
OpenSSL_1_0_1-stable
OpenSSL_1_0_0-stable
OpenSSL_0_9_8-stable
OpenSSL-fips-1_2-stable
OpenSSL-fips-0_9_8-stable
openssl-3.0.13
openssl-3.1.5
openssl-3.2.1
openssl-3.2.0
openssl-3.2.0-beta1
openssl-3.0.12
openssl-3.1.4
openssl-3.2.0-alpha2
openssl-3.0.11
openssl-3.1.3
OpenSSL_1_1_1w
openssl-3.2.0-alpha1
OpenSSL_1_1_1v
openssl-3.0.10
openssl-3.1.2
OpenSSL_1_1_1u
openssl-3.0.9
openssl-3.1.1
openssl-3.1.0
openssl-3.0.8
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (27)
标签 (371)
master
feature/dtls-1.3
openssl-3.0
openssl-3.1
openssl-3.2
openssl-3.3
feature/quic-server
gost-engines-dir
OpenSSL_1_1_1-stable
OpenSSL_1_0_2-stable
OpenSSL_1_1_0-stable
OpenSSL-fips-2_0-stable
OpenSSL-fips-2_0-dev
tls1.3-draft-18
tls1.3-draft-19
OpenSSL_1_0_1-stable
OpenSSL_1_0_0-stable
OpenSSL_0_9_8-stable
OpenSSL-fips-1_2-stable
OpenSSL-fips-0_9_8-stable
openssl-3.0.13
openssl-3.1.5
openssl-3.2.1
openssl-3.2.0
openssl-3.2.0-beta1
openssl-3.0.12
openssl-3.1.4
openssl-3.2.0-alpha2
openssl-3.0.11
openssl-3.1.3
OpenSSL_1_1_1w
openssl-3.2.0-alpha1
OpenSSL_1_1_1v
openssl-3.0.10
openssl-3.1.2
OpenSSL_1_1_1u
openssl-3.0.9
openssl-3.1.1
openssl-3.1.0
openssl-3.0.8
openssl
/
crypto
/
buffer
/
buffer.c
openssl
/
crypto
/
buffer
/
buffer.c
buffer.c 3.91 KB
一键复制 编辑 原始数据 按行查看 历史
Richard Levitte 提交于 2022年09月29日 19:57 +08:00 . Stop raising ERR_R_MALLOC_FAILURE in most places
/*
* Copyright 1995-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 "internal/cryptlib.h"
#include <openssl/buffer.h>
/*
* LIMIT_BEFORE_EXPANSION is the maximum n such that (n+3)/3*4 < 2**31. That
* function is applied in several functions in this file and this limit
* ensures that the result fits in an int.
*/
#define LIMIT_BEFORE_EXPANSION 0x5ffffffc
BUF_MEM *BUF_MEM_new_ex(unsigned long flags)
{
BUF_MEM *ret;
ret = BUF_MEM_new();
if (ret != NULL)
ret->flags = flags;
return ret;
}
BUF_MEM *BUF_MEM_new(void)
{
BUF_MEM *ret;
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL)
return NULL;
return ret;
}
void BUF_MEM_free(BUF_MEM *a)
{
if (a == NULL)
return;
if (a->data != NULL) {
if (a->flags & BUF_MEM_FLAG_SECURE)
OPENSSL_secure_clear_free(a->data, a->max);
else
OPENSSL_clear_free(a->data, a->max);
}
OPENSSL_free(a);
}
/* Allocate a block of secure memory; copy over old data if there
* was any, and then free it. */
static char *sec_alloc_realloc(BUF_MEM *str, size_t len)
{
char *ret;
ret = OPENSSL_secure_malloc(len);
if (str->data != NULL) {
if (ret != NULL) {
memcpy(ret, str->data, str->length);
OPENSSL_secure_clear_free(str->data, str->length);
str->data = NULL;
}
}
return ret;
}
size_t BUF_MEM_grow(BUF_MEM *str, size_t len)
{
char *ret;
size_t n;
if (str->length >= len) {
str->length = len;
return len;
}
if (str->max >= len) {
if (str->data != NULL)
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return len;
}
/* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
if (len > LIMIT_BEFORE_EXPANSION) {
ERR_raise(ERR_LIB_BUF, ERR_R_PASSED_INVALID_ARGUMENT);
return 0;
}
n = (len + 3) / 3 * 4;
if ((str->flags & BUF_MEM_FLAG_SECURE))
ret = sec_alloc_realloc(str, n);
else
ret = OPENSSL_realloc(str->data, n);
if (ret == NULL) {
len = 0;
} else {
str->data = ret;
str->max = n;
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return len;
}
size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
{
char *ret;
size_t n;
if (str->length >= len) {
if (str->data != NULL)
memset(&str->data[len], 0, str->length - len);
str->length = len;
return len;
}
if (str->max >= len) {
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return len;
}
/* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
if (len > LIMIT_BEFORE_EXPANSION) {
ERR_raise(ERR_LIB_BUF, ERR_R_PASSED_INVALID_ARGUMENT);
return 0;
}
n = (len + 3) / 3 * 4;
if ((str->flags & BUF_MEM_FLAG_SECURE))
ret = sec_alloc_realloc(str, n);
else
ret = OPENSSL_clear_realloc(str->data, str->max, n);
if (ret == NULL) {
len = 0;
} else {
str->data = ret;
str->max = n;
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return len;
}
void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size)
{
size_t i;
if (in) {
out += size - 1;
for (i = 0; i < size; i++)
*out-- = *in++;
} else {
unsigned char *q;
char c;
q = out + size - 1;
for (i = 0; i < size / 2; i++) {
c = *q;
*q-- = *out;
*out++ = c;
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

fork from https://github.com/openssl/openssl
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/source-code-sync/openssl.git
git@gitee.com:source-code-sync/openssl.git
source-code-sync
openssl
openssl
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /