From d53ec6c0d06d20d040e0216a87f38a6105d72fc6 Mon Sep 17 00:00:00 2001 From: Daniel O'Callaghan Date: Sat, 15 Feb 1997 07:10:26 +0000 Subject: [PATCH] Reviewed by: Bruce Evans Guard against possible buffer overrun in filename passed. Another candidate for 2.2. --- lib/libc/db/hash/ndbm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index be6ff72859a9..2e8165d2b8b7 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -47,6 +47,7 @@ static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94"; #include #include +#include #include #include "hash.h" @@ -70,6 +71,11 @@ dbm_open(file, flags, mode) info.cachesize = 0; info.hash = NULL; info.lorder = 0; + + if( strlen(file) >= sizeof(path) - strlen(DBM_SUFFIX)) { + errno = ENAMETOOLONG; + return(NULL); + } (void)strcpy(path, file); (void)strcat(path, DBM_SUFFIX); return ((DBM *)__hash_open(path, flags, mode, &info, 0));