pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Efimtsev Fjodor <f.efimtsev@ftdata.ru>
To: exclusion@gmail.com <exclusion@gmail.com>
Cc: Grigorev Jurij <ju.grigorev@ftdata.ru>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Re: Importing pg_bsd_indent into our source tree
Date: Mon, 7 Sep 2026 07:10:51 +0000
Message-ID: <8f9b2d2a11024e2ba03d072afc981ebf@localhost.localdomain> (raw)

Hi Alexander,

thank you for your patch. 
I think your patched version of strspn() assumes that all of these are true:
- s1 is NULL-terminated or has characters not in s2;
- s2 doesn't contain '\n';
- s1 is not an empty string (pointing to NULL).

Also it redefines a libc function with a macro which doesn't seem very clean.

The attached version is safer in that it is bounded and avoids shadowing a stdlib function.

Regards,
Fedor Efimtsev=

Attachments:

0001-fix-sanitizer-warning-in-src-tools-pg_bsd_indent-lex.patch (text/x-patch, 1.8K) download From 2830f066ca295d3731639a9f577cf5f4c7cf8076 Mon Sep 17 00:00:00 2001 From: Fedor Efimtsev <f.efimtsev@ftdata.ru> Date: Mon, 7 Sep 2026 13:40:56 +0700 Subject: [PATCH] fix sanitizer warning in src/tools/pg_bsd_indent/lexi.c --- src/tools/pg_bsd_indent/lexi.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/tools/pg_bsd_indent/lexi.c b/src/tools/pg_bsd_indent/lexi.c index e846188d6f4..7f28e631f43 100644 --- a/src/tools/pg_bsd_indent/lexi.c +++ b/src/tools/pg_bsd_indent/lexi.c @@ -212,6 +212,34 @@ is_func_definition(char *tp) return false; } +static size_t +indent_strspn(const char *s1, const char *s2, const char *end) +{ + const char *p = s1; + + while (p < end && *p != '\n' && *p != '\0') + { + const char *spanp; + bool found = false; + + for (spanp = s2; *spanp != '\0'; spanp++) + { + if ((unsigned char) *spanp == (unsigned char) *p) + { + found = true; + break; + } + } + + if (!found) + break; + + p++; + } + + return p - s1; +} + int lexi(struct parser_state *state) { @@ -255,11 +283,11 @@ lexi(struct parser_state *state) int len; if (buf_ptr[1] == 'b' || buf_ptr[1] == 'B') - len = strspn(buf_ptr + 2, "01") + 2; + len = indent_strspn(buf_ptr + 2, "01", buf_end) + 2; else if (buf_ptr[1] == 'x' || buf_ptr[1] == 'X') - len = strspn(buf_ptr + 2, "0123456789ABCDEFabcdef") + 2; + len = indent_strspn(buf_ptr + 2, "0123456789ABCDEFabcdef", buf_end) + 2; else - len = strspn(buf_ptr + 1, "012345678") + 1; + len = indent_strspn(buf_ptr + 1, "012345678", buf_end) + 1; if (len > 0) { CHECK_SIZE_TOKEN(len); memcpy(e_token, buf_ptr, len); -- 2.55.0

view thread (22+ messages)

Message-ID: <8f9b2d2a11024e2ba03d072afc981ebf@localhost.localdomain>
Permalink:  ../8f9b2d2a11024e2ba03d072afc981ebf@localhost.localdomain/
Also on:    postgresql.org/message-id/8f9b2d2a11024e2ba03d072afc981ebf@localhost.localdomain

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: f.efimtsev@ftdata.ru, exclusion@gmail.com, ju.grigorev@ftdata.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Importing pg_bsd_indent into our source tree
  In-Reply-To: <8f9b2d2a11024e2ba03d072afc981ebf@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox