-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
When initializing a DBPointer, the size of the struct's id buffer (25) is provided to strncpy. We should actually specify 24, since that is the typical length provided to the function for valid input.
php_phongo_dbpointer_init is called from two context:
- php_phongo_dbpointer_init_from_hash, which passes results from Z_STRVAL_P and Z_STRLEN_P. The length will be 24 in most cases.
- php_phongo_dbpointer_clone_object, which passes another original struct's id buffer and a fixed size of 24
Note that bson_oid_is_valid accepts a length of 25, provided that byte is a null terminator. Otherwise, 24 is required.
Secondly, although we can assume that internal struct was zero-allocated, it may be safer to explicitly set the null byte after copying:
strncpy(intern->id, id, sizeof(intern->id) - 1); intern->id[24] = '\0';
Alternatively, memset the entire structure first:
memset(intern->id, 0, sizeof(intern->id); strncpy(intern->id, id, sizeof(intern->id) - 1);
- is related to
-
PHPC-1027 Introduce classes for deprecated BSON types
- Closed