Replace BIO_snprintf with snprintf within the library

Our BIO_snprintf is just a thin wrapper over the libc one, and we
already call it directly in other places. Just call the libc one
consistently.

Change-Id: Ia7daf26b9789ddcecab67118c4ec4a077aad5a22
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61685
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
chromium-stable
David Benjamin 1 year ago committed by Boringssl LUCI CQ
parent a4f8755f8e
commit 23d6e4cce9
  1. 6
      crypto/asn1/a_gentm.c
  2. 14
      crypto/asn1/a_strex.c
  3. 6
      crypto/asn1/a_utctm.c
  4. 8
      crypto/bio/bio_test.cc
  5. 2
      crypto/bio/connect.c
  6. 2
      crypto/bytestring/cbs.c
  7. 2
      crypto/conf/conf.c
  8. 16
      crypto/err/err.c
  9. 2
      crypto/fipsmodule/ec/p256-nistz_test.cc
  10. 3
      crypto/x509/by_dir.c
  11. 5
      crypto/x509v3/v3_alt.c
  12. 2
      decrepit/ssl/ssl_decrepit.c
  13. 4
      ssl/ssl_cipher.cc

@ -123,9 +123,9 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
}
char buf[16];
BIO_snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
data.tm_year + 1900, data.tm_mon + 1, data.tm_mday, data.tm_hour,
data.tm_min, data.tm_sec);
snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ", data.tm_year + 1900,
data.tm_mon + 1, data.tm_mday, data.tm_hour, data.tm_min,
data.tm_sec);
int free_s = 0;
if (s == NULL) {

@ -89,18 +89,18 @@ static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes,
char buf[16]; // Large enough for "\\W01234567".
unsigned char u8 = (unsigned char)c;
if (c > 0xffff) {
BIO_snprintf(buf, sizeof(buf), "\\W%08" PRIX32, c);
snprintf(buf, sizeof(buf), "\\W%08" PRIX32, c);
} else if (c > 0xff) {
BIO_snprintf(buf, sizeof(buf), "\\U%04" PRIX32, c);
snprintf(buf, sizeof(buf), "\\U%04" PRIX32, c);
} else if ((flags & ASN1_STRFLGS_ESC_MSB) && c > 0x7f) {
BIO_snprintf(buf, sizeof(buf), "\\%02X", c);
snprintf(buf, sizeof(buf), "\\%02X", c);
} else if ((flags & ASN1_STRFLGS_ESC_CTRL) && is_control_character(c)) {
BIO_snprintf(buf, sizeof(buf), "\\%02X", c);
snprintf(buf, sizeof(buf), "\\%02X", c);
} else if (flags & ASN1_STRFLGS_ESC_2253) {
// See RFC 2253, sections 2.4 and 4.
if (c == '\\' || c == '"') {
// Quotes and backslashes are always escaped, quoted or not.
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
snprintf(buf, sizeof(buf), "\\%c", (int)c);
} else if (c == ',' || c == '+' || c == '<' || c == '>' || c == ';' ||
(is_first && (c == ' ' || c == '#')) ||
(is_last && (c == ' '))) {
@ -111,13 +111,13 @@ static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes,
}
return maybe_write(out, &u8, 1) ? 1 : -1;
}
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
snprintf(buf, sizeof(buf), "\\%c", (int)c);
} else {
return maybe_write(out, &u8, 1) ? 1 : -1;
}
} else if ((flags & ESC_FLAGS) && c == '\\') {
// If any escape flags are set, also escape backslashes.
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
snprintf(buf, sizeof(buf), "\\%c", (int)c);
} else {
return maybe_write(out, &u8, 1) ? 1 : -1;
}

@ -124,9 +124,9 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, int offset_d
}
char buf[14];
BIO_snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
data.tm_year % 100, data.tm_mon + 1, data.tm_mday, data.tm_hour,
data.tm_min, data.tm_sec);
snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ", data.tm_year % 100,
data.tm_mon + 1, data.tm_mday, data.tm_hour, data.tm_min,
data.tm_sec);
int free_s = 0;
if (s == NULL) {

@ -48,7 +48,7 @@ static std::string LastSocketError() { return strerror(errno); }
#else
static std::string LastSocketError() {
char buf[DECIMAL_SIZE(int) + 1];
BIO_snprintf(buf, sizeof(buf), "%d", WSAGetLastError());
snprintf(buf, sizeof(buf), "%d", WSAGetLastError());
return buf;
}
#endif
@ -99,11 +99,9 @@ TEST(BIOTest, SocketConnect) {
char hostname[80];
if (ss.ss_family == AF_INET6) {
BIO_snprintf(hostname, sizeof(hostname), "[::1]:%d",
ntohs(sin6->sin6_port));
snprintf(hostname, sizeof(hostname), "[::1]:%d", ntohs(sin6->sin6_port));
} else if (ss.ss_family == AF_INET) {
BIO_snprintf(hostname, sizeof(hostname), "127.0.0.1:%d",
ntohs(sin->sin_port));
snprintf(hostname, sizeof(hostname), "127.0.0.1:%d", ntohs(sin->sin_port));
}
// Connect to it with a connect BIO.

@ -532,7 +532,7 @@ int BIO_set_conn_port(BIO *bio, const char *port_str) {
int BIO_set_conn_int_port(BIO *bio, const int *port) {
char buf[DECIMAL_SIZE(int) + 1];
BIO_snprintf(buf, sizeof(buf), "%d", *port);
snprintf(buf, sizeof(buf), "%d", *port);
return BIO_set_conn_port(bio, buf);
}

@ -694,7 +694,7 @@ int CBS_is_unsigned_asn1_integer(const CBS *cbs) {
static int add_decimal(CBB *out, uint64_t v) {
char buf[DECIMAL_SIZE(uint64_t) + 1];
BIO_snprintf(buf, sizeof(buf), "%" PRIu64, v);
snprintf(buf, sizeof(buf), "%" PRIu64, v);
return CBB_add_bytes(out, (const uint8_t *)buf, strlen(buf));
}

@ -574,7 +574,7 @@ err:
if (out_error_line != NULL) {
*out_error_line = eline;
}
BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
snprintf(btmp, sizeof btmp, "%ld", eline);
ERR_add_error_data(2, "line ", btmp);
if (v != NULL) {

@ -554,17 +554,17 @@ char *ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
char lib_buf[64], reason_buf[64];
if (lib_str == NULL) {
BIO_snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
lib_str = lib_buf;
}
if (reason_str == NULL) {
BIO_snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
reason_str = reason_buf;
}
snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
reason_str = reason_buf;
}
BIO_snprintf(buf, len, "error:%08" PRIx32 ":%s:OPENSSL_internal:%s",
packed_error, lib_str, reason_str);
snprintf(buf, len, "error:%08" PRIx32 ":%s:OPENSSL_internal:%s", packed_error,
lib_str, reason_str);
if (strlen(buf) == len - 1) {
// output may be truncated; make sure we always have 5 colon-separated
@ -617,8 +617,8 @@ void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
}
ERR_error_string_n(packed_error, buf, sizeof(buf));
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
file, line, (flags & ERR_FLAG_STRING) ? data : "");
snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf, file,
line, (flags & ERR_FLAG_STRING) ? data : "");
if (callback(buf2, strlen(buf2), ctx) <= 0) {
break;
}

@ -194,7 +194,7 @@ static std::string FieldElementToString(const BN_ULONG a[P256_LIMBS]) {
std::string ret;
for (size_t i = P256_LIMBS-1; i < P256_LIMBS; i--) {
char buf[2 * BN_BYTES + 1];
BIO_snprintf(buf, sizeof(buf), BN_HEX_FMT2, a[i]);
snprintf(buf, sizeof(buf), BN_HEX_FMT2, a[i]);
ret += buf;
}
return ret;

@ -312,8 +312,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
hent = NULL;
}
for (;;) {
BIO_snprintf(b->data, b->max, "%s/%08lx.%s%d", ent->dir, h, postfix,
k);
snprintf(b->data, b->max, "%s/%08lx.%s%d", ent->dir, h, postfix, k);
#ifndef OPENSSL_NO_POSIX_IO
#if defined(_WIN32) && !defined(stat)
#define stat _stat

@ -173,13 +173,12 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(const X509V3_EXT_METHOD *method,
case GEN_IPADD:
p = gen->d.ip->data;
if (gen->d.ip->length == 4) {
BIO_snprintf(oline, sizeof(oline), "%d.%d.%d.%d", p[0], p[1], p[2],
p[3]);
snprintf(oline, sizeof(oline), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
} else if (gen->d.ip->length == 16) {
oline[0] = 0;
for (i = 0; i < 8; i++) {
uint16_t v = ((uint16_t)p[0] << 8) | p[1];
BIO_snprintf(htmp, sizeof(htmp), "%X", v);
snprintf(htmp, sizeof(htmp), "%X", v);
p += 2;
OPENSSL_strlcat(oline, htmp, sizeof(oline));
if (i != 7) {

@ -150,7 +150,7 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
break;
}
int r = BIO_snprintf(buf, sizeof(buf), "%s/%s", path, dirent->d_name);
int r = snprintf(buf, sizeof(buf), "%s/%s", path, dirent->d_name);
if (r <= 0 ||
r >= (int)sizeof(buf) ||
!SSL_add_file_cert_subjects_to_stack(stack, buf)) {

@ -1682,8 +1682,8 @@ const char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf,
return "Buffer too small";
}
BIO_snprintf(buf, len, "%-23s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n",
cipher->name, kx, au, enc, mac);
snprintf(buf, len, "%-23s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n", cipher->name,
kx, au, enc, mac);
return buf;
}

Loading…
Cancel
Save