]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
profile: protect from negative refcnt in persvc
authorShachar Sharon <ssharon@redhat.com>
Mon, 13 Apr 2026 08:43:42 +0000 (11:43 +0300)
committerAnoop C S <anoopcs@samba.org>
Thu, 21 May 2026 05:38:37 +0000 (05:38 +0000)
The function `smbprofile_persvc_unref` may be called by smb2_service.c
due to `on_err_call_profile_unref`. In such case, need to protect from
possible negative refcnt of persvc entry.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
source3/profile/profile.c

index 0465f0f5cd59928a08dabe63f75842c480f1f417..12a9aef0bec5b8241f5197ba6128a328aef3fd0f 100644 (file)
@@ -472,7 +472,13 @@ void smbprofile_persvc_unref(int snum)
 
        persvc = smbprofile_persvc_lookup(snum);
        if (persvc != NULL) {
-               persvc->refcnt--;
+               if (persvc->refcnt > 0) {
+                       persvc->refcnt--;
+               } else {
+                       DBG_INFO("Profile persvc-entry with zero refcnt "
+                                "(snum %d)\n",
+                                snum);
+               }
        }
 }