Skip to content

Commit 3154731

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/odbc: do not mutate the caller's DSN string
2 parents 1ca5d65 + f9b6254 commit 3154731

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

ext/odbc/php_odbc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,9 +2076,9 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
20762076

20772077
/* Force UID and PWD to be set in the DSN */
20782078
if (use_uid_arg || use_pwd_arg) {
2079-
db_end--;
2080-
if ((unsigned char)*(db_end) == ';') {
2081-
*db_end = '\0';
2079+
size_t base_len = db_len;
2080+
if (base_len > 0 && db[base_len - 1] == ';') {
2081+
base_len--;
20822082
}
20832083

20842084
char *uid_quoted = NULL, *pwd_quoted = NULL;
@@ -2094,7 +2094,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
20942094
}
20952095

20962096
if (!use_pwd_arg) {
2097-
spprintf(&ldb, 0, "%s;UID=%s;", db, uid_quoted);
2097+
spprintf(&ldb, 0, "%.*s;UID=%s;", (int) base_len, db, uid_quoted);
20982098
}
20992099
}
21002100

@@ -2109,12 +2109,12 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
21092109
}
21102110

21112111
if (!use_uid_arg) {
2112-
spprintf(&ldb, 0, "%s;PWD=%s;", db, pwd_quoted);
2112+
spprintf(&ldb, 0, "%.*s;PWD=%s;", (int) base_len, db, pwd_quoted);
21132113
}
21142114
}
21152115

21162116
if (use_uid_arg && use_pwd_arg) {
2117-
spprintf(&ldb, 0, "%s;UID=%s;PWD=%s;", db, uid_quoted, pwd_quoted);
2117+
spprintf(&ldb, 0, "%.*s;UID=%s;PWD=%s;", (int) base_len, db, uid_quoted, pwd_quoted);
21182118
}
21192119

21202120
if (uid_quoted && should_quote_uid) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
odbc_connect() must not mutate the caller's DSN string
3+
--EXTENSIONS--
4+
odbc
5+
--FILE--
6+
<?php
7+
/* The '=' selects the connection-string form and the trailing ';' is what the
8+
* UID/PWD assembly used to overwrite with a NUL, in the caller's own buffer. */
9+
$dsn = 'Driver=DoesNotExist;Database=x;SS001;';
10+
const DSN_CONST = 'Driver=DoesNotExist;Database=x;SS001_CONST;';
11+
12+
@odbc_connect($dsn, 'u', 'p');
13+
@odbc_connect(DSN_CONST, 'u', 'p');
14+
15+
var_dump($dsn);
16+
var_dump(DSN_CONST);
17+
?>
18+
--EXPECT--
19+
string(37) "Driver=DoesNotExist;Database=x;SS001;"
20+
string(43) "Driver=DoesNotExist;Database=x;SS001_CONST;"

0 commit comments

Comments
 (0)