The branch main has been updated by bnovkov:

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

commit 108e2d1137aabc65db3cff545615e9e8927dbe23
Author:     Bojan Novković <bnov...@freebsd.org>
AuthorDate: 2025-07-24 15:07:34 +0000
Commit:     Bojan Novković <bnov...@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;
 

Reply via email to