Skip to content

Commit c910d2c

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/odbc: do not mutate the caller's DSN string
2 parents 7522c49 + 3154731 commit c910d2c

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
@@ -1952,9 +1952,9 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
19521952

19531953
/* Force UID and PWD to be set in the DSN */
19541954
if (use_uid_arg || use_pwd_arg) {
1955-
db_end--;
1956-
if ((unsigned char)*(db_end) == ';') {
1957-
*db_end = '\0';
1955+
size_t base_len = db_len;
1956+
if (base_len > 0 && db[base_len - 1] == ';') {
1957+
base_len--;
19581958
}
19591959

19601960
char *uid_quoted = NULL, *pwd_quoted = NULL;
@@ -1970,7 +1970,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
19701970
}
19711971

19721972
if (!use_pwd_arg) {
1973-
spprintf(&ldb, 0, "%s;UID=%s;", db, uid_quoted);
1973+
spprintf(&ldb, 0, "%.*s;UID=%s;", (int) base_len, db, uid_quoted);
19741974
}
19751975
}
19761976

@@ -1985,12 +1985,12 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
19851985
}
19861986

19871987
if (!use_uid_arg) {
1988-
spprintf(&ldb, 0, "%s;PWD=%s;", db, pwd_quoted);
1988+
spprintf(&ldb, 0, "%.*s;PWD=%s;", (int) base_len, db, pwd_quoted);
19891989
}
19901990
}
19911991

19921992
if (use_uid_arg && use_pwd_arg) {
1993-
spprintf(&ldb, 0, "%s;UID=%s;PWD=%s;", db, uid_quoted, pwd_quoted);
1993+
spprintf(&ldb, 0, "%.*s;UID=%s;PWD=%s;", (int) base_len, db, uid_quoted, pwd_quoted);
19941994
}
19951995

19961996
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)