From 94576fd805c9a88cb6fecf27215ec5d4fb86f278 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 3 Dec 2013 20:26:09 +0100 Subject: crypto: Fix bug in change_basename strrchr used on non null-terminated string. --- lib/crypto/c_src/crypto.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c index 322f08be64..7567a08894 100644 --- a/lib/crypto/c_src/crypto.c +++ b/lib/crypto/c_src/crypto.c @@ -548,9 +548,12 @@ static ERL_NIF_TERM atom_onbasis; #ifdef HAVE_DYNAMIC_CRYPTO_LIB static int change_basename(ErlNifBinary* bin, char* buf, int bufsz, const char* newfile) { - const unsigned char* p = (unsigned char*)strrchr((char*)bin->data, '/'); - int i = (p == NULL) ? 0 : (p+1) - bin->data; + int i; + for (i = bin->size; i > 0; i--) { + if (bin->data[i-1] == '/') + break; + } if (i + strlen(newfile) >= bufsz) { PRINTF_ERR0("CRYPTO: lib name too long"); return 0; -- cgit v1.2.3