some SCRAM read_any_attr() confusion - Mailing list pgsql-hackers

From Peter Eisentraut
Subject some SCRAM read_any_attr() confusion
Date
Msg-id 2fb8a15b-de35-682d-a77b-edcc9c52fa12@2ndquadrant.com
Whole thread Raw
Responses Re: some SCRAM read_any_attr() confusion  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
I was a bit confused by some of the comments around the SCRAM function
read_any_attr(), used to skip over extensions.

The comment "Returns NULL if there is attribute.", besides being
strangely worded, appears to be wrong anyway, because the function never
returns NULL.

This lead me to wonder how this loop would terminate if there is no "p"
attribute in the message:

    /* ignore optional extensions */
    do
    {
        proof = p - 1;
        value = read_any_attr(&p, &attr);
    } while (attr != 'p');

What actually happens is

ERROR:  malformed SCRAM message
DETAIL:  Attribute expected, but found invalid character "0x00".

which serves the purpose but was probably not quite intended that way.

I propose the attached patch to clean this up a bit, with better
comments and a better error message.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Binguo Bao
Date:
Subject: Re: [proposal] de-TOAST'ing using a iterator
Next
From: Michael Paquier
Date:
Subject: Re: some SCRAM read_any_attr() confusion