Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jul 2025 09:23:23 GMT
From:      Bojan =?utf-8?Q?Novkovi=C4=87?= <bnovkov@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 108e2d1137aa - main - db/hash.c: Do not return an error when opening a missing database with O_CREAT
Message-ID:  <202507250923.56P9NNxm092086@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bnovkov:

URL: https://cgit.FreeBSD.org/src/commit/?id=108e2d1137aabc65db3cff545615e9e8927dbe23

commit 108e2d1137aabc65db3cff545615e9e8927dbe23
Author:     Bojan Novković <bnovkov@FreeBSD.org>
AuthorDate: 2025-07-24 15:07:34 +0000
Commit:     Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2025-07-25 09:22:44 +0000

    db/hash.c: Do not return an error when opening a missing database with O_CREAT
    
    dbm_open currently returns an error when opening a missing database
    with O_CREAT but creates the request database file. This is caused
    by a buggy check in __hash_open which attempts to detect a new
    (or empty) database file, but fails to take the O_CREAT flag into
    account.
    
    Fix this by expanding the check to include O_CREAT.
    
    Fixes:  edcdc752ecdd
    Sponsored by:   Klara, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D51491
---
 lib/libc/db/hash/hash.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index 7a66f5443d94..cc96fb5ce326 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -120,7 +120,8 @@ __hash_open(const char *file, int flags, int mode,
 		if ((hashp->fp = _open(file, flags | O_CLOEXEC, mode)) == -1)
 			RETURN_ERROR(errno, error0);
 		new_table = _fstat(hashp->fp, &statbuf) == 0 &&
-		    statbuf.st_size == 0 && (flags & O_ACCMODE) != O_RDONLY;
+		    statbuf.st_size == 0 &&
+		    ((flags & O_ACCMODE) != O_RDONLY || (flags & O_CREAT) != 0);
 	} else
 		new_table = 1;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202507250923.56P9NNxm092086>