From: | Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> |
---|---|
To: | Daniel Gustafsson <daniel(at)yesql(dot)se> |
Cc: | Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>, Richard Guo <guofenglinux(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c) |
Date: | 2024-07-01 17:38:20 |
Message-ID: | CAEudQAq_VsYzTQOAGeqvZ2fyYwU2ZNQsfCPhQMhjiTOH5=Pc3Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Em seg., 1 de jul. de 2024 às 14:35, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
escreveu:
> Em seg., 1 de jul. de 2024 às 06:20, Daniel Gustafsson <daniel(at)yesql(dot)se>
> escreveu:
>
>> > On 27 Jun 2024, at 13:50, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
>>
>> > Now with file patch really attached.
>>
>> - if (strlen(backupidstr) > MAXPGPATH)
>> + if (strlcpy(state->name, backupidstr, sizeof(state->name)) >=
>> sizeof(state->name))
>> ereport(ERROR,
>>
>> Stylistic nit perhaps, I would keep the strlen check here and just
>> replace the
>> memcpy with strlcpy. Using strlen in the error message check makes the
>> code
>> more readable.
>>
> This is not performance-critical code, so I see no problem using strlen,
> for the sake of readability.
>
>
>>
>> - char name[MAXPGPATH + 1];
>> + char name[MAXPGPATH];/* backup label name */
>>
>> With the introduced use of strlcpy, why do we need to change this field?
>>
> The part about being the only reference in the entire code that uses
> MAXPGPATH + 1.
> MAXPGPATH is defined as 1024, so MAXPGPATH +1 is 1025.
> I think this hurts the calculation of the array index,
> preventing power two optimization.
>
> Another argument is that all other paths have a 1023 size limit,
> I don't see why the backup label would have to be different.
>
> New version patch attached.
>
Sorry for v5, I forgot to update the patch and it was an error.
best regards,
Ranier Vilela
Attachment | Content-Type | Size |
---|---|---|
v6-avoid-incomplete-copy-string-do_pg_backup_start.patch | application/octet-stream | 1.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrey M. Borodin | 2024-07-01 17:40:37 | Commitfest manager for July 2024 |
Previous Message | Ranier Vilela | 2024-07-01 17:35:49 | Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c) |