Skip to content

Commit 03713ac

Browse files
committed
Fix locale dependent parsing of PostgreSQL version number
Version numbers are not supposed to be localized, so we must not apply locale dependent parsing with `atof()`. Using `php_version_compare()` might even be better. Closes GH-6668.
1 parent ca7547c commit 03713ac

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ext/pgsql/pgsql.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,10 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
14241424
}
14251425
pgsql = (PGconn *) le->ptr;
14261426
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
1427-
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 7.2) {
1427+
/* consider to use php_version_compare() here */
1428+
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 7.2) {
14281429
#else
1429-
if (atof(PG_VERSION) >= 7.2) {
1430+
if (zend_strtod(PG_VERSION, NULL) >= 7.2) {
14301431
#endif
14311432
pg_result = PQexec(pgsql, "RESET ALL;");
14321433
PQclear(pg_result);
@@ -5326,9 +5327,10 @@ PHP_FUNCTION(pg_get_notify)
53265327
add_index_string(return_value, 0, pgsql_notify->relname);
53275328
add_index_long(return_value, 1, pgsql_notify->be_pid);
53285329
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
5329-
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
5330+
/* consider to use php_version_compare() here */
5331+
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
53305332
#else
5331-
if (atof(PG_VERSION) >= 9.0) {
5333+
if (zend_strtod(PG_VERSION) >= 9.0, NULL) {
53325334
#endif
53335335
#if HAVE_PQPARAMETERSTATUS
53345336
add_index_string(return_value, 2, pgsql_notify->extra);
@@ -5339,9 +5341,10 @@ PHP_FUNCTION(pg_get_notify)
53395341
add_assoc_string(return_value, "message", pgsql_notify->relname);
53405342
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
53415343
#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
5342-
if (PQprotocolVersion(pgsql) >= 3 && atof(PQparameterStatus(pgsql, "server_version")) >= 9.0) {
5344+
/* consider to use php_version_compare() here */
5345+
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
53435346
#else
5344-
if (atof(PG_VERSION) >= 9.0) {
5347+
if (zend_strtod(PG_VERSION, NULL) >= 9.0) {
53455348
#endif
53465349
#if HAVE_PQPARAMETERSTATUS
53475350
add_assoc_string(return_value, "payload", pgsql_notify->extra);

0 commit comments

Comments
 (0)