| From: | Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp> |
|---|---|
| To: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
| Cc: | "pgpool-hackers(at)lists(dot)postgresql(dot)org" <pgpool-hackers(at)lists(dot)postgresql(dot)org>, "emond(dot)papegaaij(at)gmail(dot)com" <emond(dot)papegaaij(at)gmail(dot)com> |
| Subject: | Re: Delimit query-cache key to prevent collisions |
| Date: | 2026-08-26 07:25:18 |
| Message-ID: | OS9P286MB64868467349F2C38BC23E3A394AE2@OS9P286MB6486.JPNP286.PROD.OUTLOOK.COM |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-hackers |
> Small point. Pgindent dislikes following (comment line is too long).
>
> *** /tmp/pool_memqcache.c 2026-08-17 15:20:30.384621930 +0900
> --- src/query_cache/pool_memqcache.c 2026-08-17 15:20:30.458960398 +0900
> ***************
> *** 600,606 ****
> p += d_length;
> *p = '\0';
>
> ! /* Hash the full delimited buffer (length - 1 so the final NUL is excluded). */
> pool_md5_hash(strkey, length - 1, buf);
> ereport(DEBUG1,
> (errmsg("memcache encode key"),
> --- 600,609 ----
> p += d_length;
> *p = '\0';
>
> ! /*
> ! * Hash the full delimited buffer (length - 1 so the final NUL is
> ! * excluded).
> ! */
> pool_md5_hash(strkey, length - 1, buf);
> ereport(DEBUG1,
> (errmsg("memcache encode key"),
> ***************
Thanks for pointing this out.
I've attached a patch that reformats the comment for readability.
Please take a look.
Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/
________________________________
>> I have reviewed the patch(009-encode-key-delimiter) from Emond.
>> It has also passed all regression tests.
>>
>> encode_key() constructs the cache key using md5(user || query || database) without delimiters.
>> This allows different sessions to produce identical keys
>> (e.g., "admin" + "Q" + "testdb" and "adm" + "Q" + "intestdb"),
>> leading to data leakage between users/databases.
>>
>> Changes:
>> Explicit Delimiters: Insert NUL bytes between the user, query, and database fields in the buffer.
>> Hash Full Range: Updated the hash function to process the entire byte range (including NUL separators)
>> instead of stopping at the first NUL byte.
>>
>> Thank you, Emond.
>
> I have looked into this. The patch looks good to me. Also I ran some
> of query cache related regression tests on master branch.
>
> testing 006.memqcache...ok.
> testing 007.memqcache-memcached...ok.
> testing 008.dbredirect...ok.
> testing 120.memory_leak_extended_memqcache...ok.
> testing 124.bug700_memqcache_segfault...ok.
>
> They all passed here.
Small point. Pgindent dislikes following (comment line is too long).
*** /tmp/pool_memqcache.c 2026-08-17 15:20:30.384621930 +0900
--- src/query_cache/pool_memqcache.c 2026-08-17 15:20:30.458960398 +0900
***************
*** 600,606 ****
p += d_length;
*p = '\0';
! /* Hash the full delimited buffer (length - 1 so the final NUL is excluded). */
pool_md5_hash(strkey, length - 1, buf);
ereport(DEBUG1,
(errmsg("memcache encode key"),
--- 600,609 ----
p += d_length;
*p = '\0';
! /*
! * Hash the full delimited buffer (length - 1 so the final NUL is
! * excluded).
! */
pool_md5_hash(strkey, length - 1, buf);
ereport(DEBUG1,
(errmsg("memcache encode key"),
***************
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Delimit-query-cache-key-to-prevent-collisions.patch | application/octet-stream | 2.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Koshino Taiki | 2026-08-26 09:21:30 | Convert pcp_exit_handler and wakeup_handler_parent to flag-only. |
| Previous Message | Tatsuo Ishii | 2026-08-22 00:52:30 | Propose to change error code |