From ee194c75a65ca813fc78eb2cb7eca65ce344ec7b Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 22 Jun 2023 12:43:14 -0400 Subject: [PATCH] Slightly tidy BIO_C_SET_FILENAME logic We could just use the string literal as-is. Change-Id: I2efe01fd9b020db1bb086001407bcf7fa8487551 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61045 Auto-Submit: David Benjamin Commit-Queue: David Benjamin Reviewed-by: Adam Langley Commit-Queue: Adam Langley --- crypto/bio/file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crypto/bio/file.c b/crypto/bio/file.c index 8ba9c544c..d0281c854 100644 --- a/crypto/bio/file.c +++ b/crypto/bio/file.c @@ -172,7 +172,6 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { long ret = 1; FILE *fp = (FILE *)b->ptr; FILE **fpp; - char p[4]; switch (cmd) { case BIO_CTRL_RESET: @@ -197,27 +196,28 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { case BIO_C_SET_FILENAME: file_free(b); b->shutdown = (int)num & BIO_CLOSE; + const char *mode; if (num & BIO_FP_APPEND) { if (num & BIO_FP_READ) { - OPENSSL_strlcpy(p, "a+", sizeof(p)); + mode = "a+"; } else { - OPENSSL_strlcpy(p, "a", sizeof(p)); + mode = "a"; } } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) { - OPENSSL_strlcpy(p, "r+", sizeof(p)); + mode = "r+"; } else if (num & BIO_FP_WRITE) { - OPENSSL_strlcpy(p, "w", sizeof(p)); + mode = "w"; } else if (num & BIO_FP_READ) { - OPENSSL_strlcpy(p, "r", sizeof(p)); + mode = "r"; } else { OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE); ret = 0; break; } - fp = fopen(ptr, p); + fp = fopen(ptr, mode); if (fp == NULL) { OPENSSL_PUT_SYSTEM_ERROR(); - ERR_add_error_data(5, "fopen('", ptr, "','", p, "')"); + ERR_add_error_data(5, "fopen('", ptr, "','", mode, "')"); OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB); ret = 0; break;