Skip to content

Commit 96faed4

Browse files
committed
Made uid and pwd of odbc_connect and odbc_pconnect nullable.
add test case fix test
1 parent 7bb69d0 commit 96faed4

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

ext/odbc/odbc.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ function odbc_free_result($statement): bool {}
382382
/**
383383
* @return resource|false
384384
*/
385-
function odbc_connect(string $dsn, string $user, #[\SensitiveParameter] string $password, int $cursor_option = SQL_CUR_USE_DRIVER) {}
385+
function odbc_connect(string $dsn, ?string $user = null, #[\SensitiveParameter] ?string $password = null, int $cursor_option = SQL_CUR_USE_DRIVER) {}
386386

387387
/**
388388
* @return resource|false
389389
*/
390-
function odbc_pconnect(string $dsn, string $user, #[\SensitiveParameter] string $password, int $cursor_option = SQL_CUR_USE_DRIVER) {}
390+
function odbc_pconnect(string $dsn, ?string $user = null, #[\SensitiveParameter] ?string $password = null, int $cursor_option = SQL_CUR_USE_DRIVER) {}
391391

392392
/** @param resource $odbc */
393393
function odbc_close($odbc): void {}

ext/odbc/odbc_arginfo.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/odbc/php_odbc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,8 +2098,8 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int
20982098

20992099
size_t db_len = strlen(db);
21002100
char *db_end = db + db_len;
2101-
bool use_uid_arg = !php_memnistr(db, "uid=", strlen("uid="), db_end);
2102-
bool use_pwd_arg = !php_memnistr(db, "pwd=", strlen("pwd="), db_end);
2101+
bool use_uid_arg = uid != NULL && !php_memnistr(db, "uid=", strlen("uid="), db_end);
2102+
bool use_pwd_arg = pwd != NULL && !php_memnistr(db, "pwd=", strlen("pwd="), db_end);
21032103

21042104
/* Force UID and PWD to be set in the DSN */
21052105
if (use_uid_arg || use_pwd_arg) {
@@ -2190,18 +2190,19 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int
21902190
/* {{{ odbc_do_connect */
21912191
void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
21922192
{
2193-
char *db, *uid, *pwd;
2193+
char *db, *uid=NULL, *pwd=NULL;
21942194
size_t db_len, uid_len, pwd_len;
21952195
zend_long pv_opt = SQL_CUR_DEFAULT;
21962196
odbc_connection *db_conn;
21972197
int cur_opt;
21982198

2199-
/* Now an optional 4th parameter specifying the cursor type
2200-
* defaulting to the cursors default
2201-
*/
2202-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &db, &db_len, &uid, &uid_len, &pwd, &pwd_len, &pv_opt) == FAILURE) {
2203-
RETURN_THROWS();
2204-
}
2199+
ZEND_PARSE_PARAMETERS_START(1, 4)
2200+
Z_PARAM_STRING(db, db_len)
2201+
Z_PARAM_OPTIONAL
2202+
Z_PARAM_STRING_OR_NULL(uid, uid_len)
2203+
Z_PARAM_STRING_OR_NULL(pwd, pwd_len)
2204+
Z_PARAM_LONG(pv_opt)
2205+
ZEND_PARSE_PARAMETERS_END();
22052206

22062207
cur_opt = pv_opt;
22072208

ext/odbc/tests/odbc_connect_001.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ if ($conn) odbc_close($conn);
3333

3434
echo "dsn with correct credentials / incorrect user / incorrect password\n";
3535
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}", 'hoge', 'fuga');
36+
echo $conn ? "Connected.\n\n" : "";
37+
if ($conn) odbc_close($conn);
38+
39+
echo "dsn with correct credentials / null user / null password\n";
40+
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}", null, null);
41+
echo $conn ? "Connected.\n\n" : "";
42+
if ($conn) odbc_close($conn);
43+
44+
echo "dsn with correct credentials / not set user / not set password\n";
45+
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}");
3646
echo $conn ? "Connected.\n" : "";
3747
if ($conn) odbc_close($conn);
3848
?>
@@ -48,3 +58,9 @@ Connected.
4858

4959
dsn with correct credentials / incorrect user / incorrect password
5060
Connected.
61+
62+
dsn with correct credentials / null user / null password
63+
Connected.
64+
65+
dsn with correct credentials / not set user / not set password
66+
Connected.

0 commit comments

Comments
 (0)