Skip to content

PHPC-1774 Fix truncation of PHP_VERSION constant in handshake metadata #1202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
#define PHONGO_DEBUG_INI_DEFAULT ""
#define PHONGO_METADATA_SEPARATOR " / "
#define PHONGO_METADATA_SEPARATOR_LEN (sizeof(PHONGO_METADATA_SEPARATOR) - 1)
#define PHONGO_METADATA_PHP_VERSION_PREFIX "PHP "
#define PHONGO_METADATA_PHP_VERSION_PREFIX_LEN (sizeof(PHONGO_METADATA_PHP_VERSION_PREFIX) - 1)

ZEND_DECLARE_MODULE_GLOBALS(mongodb)
#if defined(ZTS) && defined(COMPILE_DL_MONGODB)
Expand Down Expand Up @@ -2569,7 +2571,7 @@ static char* php_phongo_concat_handshake_data(const char* default_value, const c
size_t ret_len = strlen(default_value) + 1;

if (custom_value) {
/* Increase the length by that of the custom value as well as one byte for the separator */
/* Increase the length by that of the custom value as well as the separator length */
ret_len += custom_value_len + PHONGO_METADATA_SEPARATOR_LEN;
}

Expand All @@ -2592,9 +2594,9 @@ static void php_phongo_handshake_data_append(const char* name, size_t name_len,
char* driver_version;
char* full_platform;

php_version_string_len = strlen(PHP_VERSION);
php_version_string = ecalloc(sizeof(char*), 4 + php_version_string_len);
snprintf(php_version_string, 4 + php_version_string_len, "PHP %s", PHP_VERSION);
php_version_string_len = strlen(PHP_VERSION) + PHONGO_METADATA_PHP_VERSION_PREFIX_LEN + 1;
php_version_string = ecalloc(sizeof(char*), php_version_string_len);
snprintf(php_version_string, php_version_string_len, "%s%s", PHONGO_METADATA_PHP_VERSION_PREFIX, PHP_VERSION);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're still missing the space that goes after the PHONGO_METADATA_PHP_VERSION_PREFIX + PHP_VERSION combo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are indeed correct. This is an issue in libmongoc which seems to append platform data without a separating space. I'm working on a fix for that, but for the time being this PR will mitigate the issue.


driver_name = php_phongo_concat_handshake_data("ext-mongodb:PHP", name, name_len);
driver_version = php_phongo_concat_handshake_data(PHP_MONGODB_VERSION, version, version_len);
Expand Down