-
Notifications
You must be signed in to change notification settings - Fork 27
Include password in persistent hash key #19
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
Conversation
Matches behaviour of other database extensions, and removes some surprise that the extension doesn't check for a valid password when reusing a connection. Of course, that must be the password the connection was created with, but that's the same for the others too. Fixes GH-18 XXX: Would like to include options, but not sure how to do this cleanly.
ibm_db2.c
Outdated
@@ -2354,10 +2354,11 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle ** | |||
/* Check if we already have a connection for this userID & database combination */ | |||
if (isPersistent) { | |||
zend_resource *entry; | |||
hKeyLen = strlen(database) + strlen(uid) + 8; | |||
hKeyLen = strlen(database) + strlen(uid) + strlen(password) + 9; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hKeyLen = strlen(database) + strlen(uid) + strlen(password) + 9; | |
hKeyLen = strlen(database) + strlen(uid) + strlen(password) + sizeof("__db2_"); |
Would be a bit more clear what the 9 means.
Ooops, I've commented on the issue. I'll copy and paste it here as well: I am not so sure that I like the fact that the password is available in clear text in memory. We don't need a cryptagraphic hash function. Most of the time only one user/password combination is used in web applications. This is also the reason why I only used a sub string of the hash and not the entire hash back then. e.g. CRC32 is more than enough. |
Yeah, I found the fact everyone else leaves it out in the open a little surprising (Maybe worth discussing with internals@....). I was going to hash it if it was easy, though I didn't want to vendor/take an additional dependency for something even as trivial as CRC32.... |
Murmur has about the same collision rate as crc32 and does have an easy implementation:
I'd just pick either the 32 or 64 bit version and be done with it.... |
I can change the PR to use murmur, if you want me to. |
Not cryptographic, but obfuscates the password for the purpose of a hash key for internal usage.
Ideally this should be constexpr, but this is C99, not C++17...
Some missed opportunities, with array hashing, but those can be addressed later. I'd rather have this merged than sitting around. |
Matches behaviour of other database extensions, and removes some surprise that the extension doesn't check for a valid password when reusing a connection. Of course, that must be the password the connection was created with, but that's the same for the others too.
Fixes GH-18
XXX: Would like to include options, but not sure how to do this cleanly.