Re: Possible to store invalid SCRAM-SHA-256 Passwords - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: Possible to store invalid SCRAM-SHA-256 Passwords
Date
Msg-id 20190423010142.GE2712@paquier.xyz
Whole thread Raw
In response to Re: Possible to store invalid SCRAM-SHA-256 Passwords  ("Jonathan S. Katz" <jkatz@postgresql.org>)
Responses Re: Possible to store invalid SCRAM-SHA-256 Passwords
Re: Possible to store invalid SCRAM-SHA-256 Passwords
List pgsql-bugs
On Mon, Apr 22, 2019 at 07:36:45PM -0400, Jonathan S. Katz wrote:
> On 4/22/19 6:42 PM, Tom Lane wrote:
>> Yeah, that's silly; why not
>>
>>      strspn(shadow_pass + 3, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN - 3
>>
>> It's not like this code isn't very well aware of the first 3 characters
>> being not like the others.
>
> I like that :) Please see attached patch, which is diff'd from the one
> upthread.

That's exactly what I would have done for that.  However...

+   if (strncmp(shadow_pass, "md5", 3) == 0 && strlen(shadow_pass) == MD5_PASSWD_LEN &&
+       strspn(shadow_pass + 3, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN - 3)
                return PASSWORD_TYPE_MD5;
There is no point for the second strlen() check, as strspn does the
same work.

Also, the extra SELECT query with regexp_replace() is a bit overkill
for the purpose, and copying again a copy of the regexp around is no
fun.

In short, I would simplify things as the attached.  What do you think?
--
Michael

Attachment

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Possible to store invalid SCRAM-SHA-256 Passwords
Next
From: Tom Lane
Date:
Subject: Re: Possible to store invalid SCRAM-SHA-256 Passwords