Browse Source

Bug 750624 - Fix Coverity (11053) Explicit null dereferenced:
slapi_dn_normalize_ext (slapd/dn.c)

https://bugzilla.redhat.com/show_bug.cgi?id=750624

Bug Description: Dereferencing null variable "d".
There is no possibility that (rc > 0) && (d == NULL), but it's
safe to check if d is not NULL before assigning '\0' to *d.

Fix Description: add checking if "d" is NULL or not before
assigning '\0' to *d.

Noriko Hosoi 14 năm trước cách đây
mục cha
commit
54a3d99a96
1 tập tin đã thay đổi với 3 bổ sung3 xóa
  1. 3 3
      ldap/servers/slapd/dn.c

+ 3 - 3
ldap/servers/slapd/dn.c

@@ -515,7 +515,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
     int chkblank = 0;
     int is_dn_syntax = 0;
 
-    if (NULL == dest) {
+    if ((NULL == dest) || (NULL == dest_len)) {
         goto bail;
     }
     if (NULL == src) {
@@ -544,7 +544,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
         }
     }
     if (0 == src_len) { /* src == "" */
-        goto bail;
+        goto bail; /* need to bail after setting up *dest and rc */
     }
 
     ends = src + src_len;
@@ -1081,7 +1081,7 @@ bail:
             }
         }
         *dest_len = 0;
-    } else if (rc > 0) {
+    } else if (d && rc > 0) {
         /* We terminate the str with NULL only when we allocate the str */
         *d = '\0';
     }