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 <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com>
diff --git a/crypto/bio/file.c b/crypto/bio/file.c index 8ba9c54..d0281c8 100644 --- a/crypto/bio/file.c +++ b/crypto/bio/file.c
@@ -172,7 +172,6 @@ long ret = 1; FILE *fp = (FILE *)b->ptr; FILE **fpp; - char p[4]; switch (cmd) { case BIO_CTRL_RESET: @@ -197,27 +196,28 @@ 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;