Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xBruo-00000003Qb1-0z0Q for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Sep 2026 10:51:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xBrun-00000001tgp-11VN for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Sep 2026 10:51:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xBrum-00000001tgd-42Pd for pgsql-hackers@lists.postgresql.org; Wed, 30 Sep 2026 10:51:56 +0000 Received: from mail-lf2-x10.google.com ([2a00:1450:4864:36::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xBruk-000000021WT-2a3n for pgsql-hackers@lists.postgresql.org; Wed, 30 Sep 2026 10:51:56 +0000 Received: by mail-lf2-x10.google.com with SMTP id 2adb3069b0e04-5b5e4f15b78so4733960e87.2 for ; Wed, 30 Sep 2026 03:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790765513; x=1791370313; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=irmQWEkr41xUoGDuEGnOavicMsnTpsUYHdJlJYAHSUM=; b=AYBQTBkrMpK5A2zcq+mHoc3U0faEX6ehHRy8RmUIDiww0FbYKVb+zVsDYpfhmazypG aRGWutBQ94DA55nVIDxGxs9mUJHPljvUhQyFD0drj/9slZWn54P3y+cylXqSTcEg3qs8 otKzdJwyoxipX7TavYIpq4oQ9UNzOJCmc8d93+NzdS0N53cmdGXfysXHu+fcOZS7555a UFmskr/HFKuFYSlH5IT7QnX41fSimDwM+Ziz+Op10VTj453D8xNnzRfGG7uctEYCT868 uOrYHRC0uqoij24wzD/dVh2ZcPbriUbJNLZwEwBB+XsC97OZz49iY6y2UAM4iM9Onddh tTQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790765513; x=1791370313; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=irmQWEkr41xUoGDuEGnOavicMsnTpsUYHdJlJYAHSUM=; b=OaHOhsCcZg78aCiY1Ogkae/wxekQb2FGz9JaKmBYVMrU+OCXZxURf58K0LUOTUq8iL NM0bUgqrouxSZxyl3m4LOsAWl3rT3pXBzM5t+LIUKebLOPnA6ZF4mtkoFF+VO7H0ygzH vVvFQzAu0rDAPe8gjJDJgnkKLQwR1pJSpH3sX8ZimTjjBZ8KemyFdWlsoaWOkC73Foe8 TyJT5iCxgvezta2M8PW5sHWu5D3yXzyc/EqtiJqy/kl5ZIaFmuU/hKRouyafF/bZQQ60 h4P2o6y+7p9fd9pvs2Jj6u047DqZoucb1+JTxZ1U27QRcIcrdsj9NIN3nk9ICQYmN4lh M2HQ== X-Gm-Message-State: AFq9FYKw6sK9SXKb7+X5HL9qpe3t4kzYfix1mhaLNNUMwDQ0/egWRUA+ pDqNrdeoP7RYFbnm+/TvQMfDQRnziGv4i2ZaVHmMOqMeoJXevKLHDGaPYnNL3ck6 X-Gm-Gg: AYBFou0Gf4Lmek/TZaqqZAuj/yeNzXjECpbo3VeDIB1huZYX0MSwqxXbZYcYJHBTPod KVkWSSOeBxFu7KxM/7pfzgkjHaL6LeWCuzJ1GeyFbss1mxl67MQ7a3XU0eSnPiFVNjAsxEZDgZw zXzleukLvlxg5/4lbodDt3rhsjk6dFUd1mtm4enlJZUc94giRLhfTWkZ8up1o1VrbipsEc9W0y0 q3AxPd4JRPcLc8gHldRkhwIDutsCGWFaGq0PawpsXMVR5A4gVOhsyEiKaDOw+OjY/yuOVz3DW0V nvQ3paTXFu/IuIh9u1Huk5Mu4GMQyVwQuaIvLj1LmbOmCWGOvEE9jbXFVP7zcXsAmwZNKx43LG2 DigNiwh8W4SjKqmjdncHg4RYOzvgzJyIy49X/lAr3gCyBgzKAaZFggwM8kGEulRtBZLK4I9jE8r RAIsnnn2Se2REKUq3+VcyouQQQVgR5Ln+M+E/vSTLrEQwdjD52rkN1Lgf4W0m3jOZB7w5po+lt4 ZPMwZM1Uq7RUiw1z7ryi4P65DeaHe4kbAqEDzbuXhKHltVFF14+wmWCkUmzEZmn X-Received: by 2002:a05:6512:2343:b0:5b8:da5a:937c with SMTP id 2adb3069b0e04-5ba405fdf29mr466202e87.17.1790765512870; Wed, 30 Sep 2026 03:51:52 -0700 (PDT) Received: from vadim-LL6FAW-09.. ([46.39.45.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5ba3fbfc97fsm258521e87.62.2026.09.30.03.51.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 03:51:52 -0700 (PDT) From: Vadim Shakirov To: pgsql-hackers@lists.postgresql.org Subject: [PATCH v1] Fix out-of-bounds access in pg_bsd_indent's parser stack Date: Wed, 30 Sep 2026 13:51:34 +0300 Message-ID: <20260930105134.568062-1-vadimsakirov5@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk parser_state stores parser state in p_stack, il, and cstk, which share the tos index. The existing overflow check used p_stack, the largest array, allowing out-of-bounds accesses to cstk and il. Size all three arrays equally. Also widen the overflow check by one element: the lbrace case pushes two entries (lbrace and then stmt), so there must be room for two more elements when parse() is entered. --- src/tools/pg_bsd_indent/indent_globs.h | 4 ++-- src/tools/pg_bsd_indent/parse.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/pg_bsd_indent/indent_globs.h b/src/tools/pg_bsd_indent/indent_globs.h index 917961bd3d6..e88dd52c891 100644 --- a/src/tools/pg_bsd_indent/indent_globs.h +++ b/src/tools/pg_bsd_indent/indent_globs.h @@ -234,8 +234,8 @@ extern int ifdef_level; struct parser_state { int last_token; int p_stack[256]; /* this is the parsers stack */ - int il[64]; /* this stack stores indentation levels */ - float cstk[32]; /* used to store case stmt indentation levels */ + int il[256]; /* this stack stores indentation levels */ + float cstk[256]; /* used to store case stmt indentation levels */ int box_com; /* set to true when we are in a "boxed" * comment. In that case, the first non-blank * char should be lined up with the / in / followed by * */ diff --git a/src/tools/pg_bsd_indent/parse.c b/src/tools/pg_bsd_indent/parse.c index 94cea724393..f50a03193e1 100644 --- a/src/tools/pg_bsd_indent/parse.c +++ b/src/tools/pg_bsd_indent/parse.c @@ -203,7 +203,7 @@ parse(int tk) /* tk: the code for the construct scanned */ } /* end of switch */ - if (ps.tos >= nitems(ps.p_stack) - 1) + if (ps.tos >= nitems(ps.p_stack) - 2) errx(1, "Parser stack overflow"); reduce(); /* see if any reduction can be done */ -- 2.43.0