瀏覽代碼

610281 - fix coverity Defect Type: Control flow issues

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

11814 DEADCODE Triaged Unassigned Bug Moderate Fix Required
string_filter_sub() ds/ldap/servers/plugins/syntaxes/string.c

Comment:
A code to update tmpbufsize was missing. This "tpbufsize = len + 1;"
is needed before slapi_ch_realloc.
351 tmpbufsize = len + 1;
352 tmpbuf = (char *) slapi_ch_realloc( tmpbuf, tmpbufsize );

Also, if (len < tmpbufsize) were true (could not be true since
tmpbufsize never have been set), bvp->bv_val was copied to buf
which is not long enough for bvp->bv_val.  The bug was also
fixed.
Noriko Hosoi 15 年之前
父節點
當前提交
c766b7ac3c
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      ldap/servers/plugins/syntaxes/string.c

+ 5 - 5
ldap/servers/plugins/syntaxes/string.c

@@ -342,15 +342,15 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
 
 		len = bvp->bv_len;
 		if ( len < sizeof(buf) ) {
-			strcpy( buf, bvp->bv_val );
 			realval = buf;
+			strncpy( realval, bvp->bv_val, sizeof(buf) );
 		} else if ( len < tmpbufsize ) {
-			strcpy( buf, bvp->bv_val );
 			realval = tmpbuf;
+			strncpy( realval, bvp->bv_val, tmpbufsize );
 		} else {
-			tmpbuf = (char *) slapi_ch_realloc( tmpbuf, len + 1 );
-			strcpy( tmpbuf, bvp->bv_val );
-			realval = tmpbuf;
+			tmpbufsize = len + 1;
+			realval = tmpbuf = (char *) slapi_ch_realloc( tmpbuf, tmpbufsize );
+			strncpy( realval, bvp->bv_val, tmpbufsize );
 		}
 		/* 3rd arg: 1 - trim leading blanks */
 		value_normalize_ext( realval, syntax, 1, &alt );