Bug 42429

Summary: [libc] [patch] hash_action called with HASH_DELETE does NOT return 1 if the key is not found
Product: Base System Reporter: GB Clark <gclarkii>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Works As Intended    
Severity: Affects Only Me CC: avos
Priority: Normal    
Version: 4.6-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
db.patch.1.txt
none
Updated patch none

Description GB Clark 2002-09-04 23:20:01 UTC
if hash_action in src/lib/libc/db/hash.c is called with HASH_DELETE, it will NOT return 1 if the key is not found as documented.

Fix: 

in hash_action if the key is not found, the default action is to return -1.  HASH_GET needs to be moved below HASH_DELETE and HASH_DELETE should return 1 instead of -1.
PR misc/42422 needs to be fixed also if dbm_delete is work properly.
Please see freebsd-hackers for email from me for the patches.
How-To-Repeat: call dbm_delete from ndbm with a non-exist key. it will return -1 instead of 1 as documented.
Comment 1 GB Clark 2003-01-09 07:31:16 UTC
Hello,

Attached is a patch to correct this bug.

GB

-- 
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
            CTHULU for President - Why choose the lesser of two evils?
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-02-20 18:36:05 UTC
Created attachment 153230 [details]
Updated patch

Here is a patch easier to read in bugzilla.

Note that the current behavior is similar to the other BSD's and the db version carried kerberos in Illumos, so it might be that it's just the documentation that needs to be updated.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:51:44 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 4 Andriy Voskoboinyk freebsd_committer freebsd_triage 2019-02-01 23:45:52 UTC
As I can see from the code and / or attached patch hash_access() with HASH_DELETE parameter when the key is not found already returns 1 - that's the value of ABNORMAL macro:

/* Return values */
#define SUCCESS  (0)
#define ERROR   (-1)
#define ABNORMAL (1)

so the patch is actually no-op.