From unknown Thu Aug 14 12:22:14 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#73985 <73985@debbugs.gnu.org> To: bug#73985 <73985@debbugs.gnu.org> Subject: Status: fix: charset.max_char may be used before being set Reply-To: bug#73985 <73985@debbugs.gnu.org> Date: Thu, 14 Aug 2025 19:22:14 +0000 retitle 73985 fix: charset.max_char may be used before being set reassign 73985 emacs submitter 73985 altermo31 severity 73985 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 24 09:02:33 2024 Received: (at submit) by debbugs.gnu.org; 24 Oct 2024 13:02:33 +0000 Received: from localhost ([127.0.0.1]:34054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3xU0-0002EN-AX for submit@debbugs.gnu.org; Thu, 24 Oct 2024 09:02:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:35696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3wJ3-00079s-4a for submit@debbugs.gnu.org; Thu, 24 Oct 2024 07:47:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3wIU-0002fK-7w for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2024 07:46:34 -0400 Received: from mail-40138.protonmail.ch ([185.70.40.138]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3wIP-000232-PW for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2024 07:46:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=e23a342ew5amvgyixj4db4r5dy.protonmail; t=1729770382; x=1730029582; bh=gaC0BhKIghCAOt/PUB5mjNTXsfPnnHG8525I7i7i51k=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=LD9YkrNuZs1ZdOvG7wsHPQEvZ+C6YRWRpXd3c0uTpe9bOfVg3pJq7gmyUlEa3lGvr AI1wbx7bRnHztHAv0zRFha6Ki+wEgGJhPTo252eZfGrWZQUA9fpQL6dkXtTSvXnIKz egsFV9y43c9L538ulBkwEMQbhVtZXXlV+lvZ+s4sdNV5KabOWr2RlRF95vKT4yiWRO 1Ckgp3hToDb54sTPDoMuYDKTvyTakJv+e2GXfvtO/Ljdn1cgj9ks4pvc4uOq4CiJYG NEbKqGNj6eT2gwC+hspNse9wJ1yl2iVW+rtCrJYNIXMfEReKQnWkJ5mSgJ83SFwYez s+D0SU0Vopt8Q== Date: Thu, 24 Oct 2024 11:46:17 +0000 To: "bug-gnu-emacs@gnu.org" From: altermo31 Subject: fix: charset.max_char may be used before being set Message-ID: Feedback-ID: 69067202:user:proton X-Pm-Message-ID: a3b0271cfc9ef68f721d3b1dc3779e058cfb7b50 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b1=_ZGwg7xAQGhHY2uGzYs1KbVimueoWtxvfqMEkzW0xdw" Received-SPF: pass client-ip=185.70.40.138; envelope-from=altermo31@proton.me; helo=mail-40138.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 24 Oct 2024 09:02:30 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --b1=_ZGwg7xAQGhHY2uGzYs1KbVimueoWtxvfqMEkzW0xdw Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Problem: If the value to be set to charset.max_char is invalid, an error occurs, but= the error uses the yet unset charset.max_char. Solution: Use the value that charset.max_char would be set to if the value wasn't inv= alid. --b1=_ZGwg7xAQGhHY2uGzYs1KbVimueoWtxvfqMEkzW0xdw Content-Type: text/x-patch; name=0001-fix-charset.max_char-may-be-used-before-being-set.patch Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=0001-fix-charset.max_char-may-be-used-before-being-set.patch RnJvbSA2NGU5NTU3YzVmNmFlNDQxNmExYTEyZmQ2ZjY4ZjBkMTk5MzFiYjk5IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBhbHRlcm1vIDwxMDc4MTQwMDArYWx0ZXJtb0B1c2Vycy5ub3Jl cGx5LmdpdGh1Yi5jb20+CkRhdGU6IFRodSwgMjQgT2N0IDIwMjQgMTM6Mzk6MDYgKzAyMDAKU3Vi amVjdDogW1BBVENIXSBmaXg6IGNoYXJzZXQubWF4X2NoYXIgbWF5IGJlIHVzZWQgYmVmb3JlIGJl aW5nIHNldAoKLS0tCiBzcmMvY2hhcnNldC5jIHwgMiArLQogMSBmaWxlIGNoYW5nZWQsIDEgaW5z ZXJ0aW9uKCspLCAxIGRlbGV0aW9uKC0pCgpkaWZmIC0tZ2l0IGEvc3JjL2NoYXJzZXQuYyBiL3Ny Yy9jaGFyc2V0LmMKaW5kZXggZThkMDgyNi4uMTRiMzNkMiAxMDA2NDQKLS0tIGEvc3JjL2NoYXJz ZXQuYworKysgYi9zcmMvY2hhcnNldC5jCkBAIC0xMDA3LDcgKzEwMDcsNyBAQCBERUZVTiAoImRl ZmluZS1jaGFyc2V0LWludGVybmFsIiwgRmRlZmluZV9jaGFyc2V0X2ludGVybmFsLAogCiAgICAg ICBpID0gQ09ERV9QT0lOVF9UT19JTkRFWCAoJmNoYXJzZXQsIGNoYXJzZXQubWF4X2NvZGUpOwog ICAgICAgaWYgKE1BWF9DSEFSIC0gY2hhcnNldC5jb2RlX29mZnNldCA8IGkpCi0JZXJyb3IgKCJV bnN1cHBvcnRlZCBtYXggY2hhcjogJWQiLCBjaGFyc2V0Lm1heF9jaGFyKTsKKwllcnJvciAoIlVu c3VwcG9ydGVkIG1heCBjaGFyOiAlZCIsIGkgKyBjaGFyc2V0LmNvZGVfb2Zmc2V0KTsKICAgICAg IGNoYXJzZXQubWF4X2NoYXIgPSBpICsgY2hhcnNldC5jb2RlX29mZnNldDsKICAgICAgIGkgPSBD T0RFX1BPSU5UX1RPX0lOREVYICgmY2hhcnNldCwgY2hhcnNldC5taW5fY29kZSk7CiAgICAgICBj aGFyc2V0Lm1pbl9jaGFyID0gaSArIGNoYXJzZXQuY29kZV9vZmZzZXQ7Ci0tIAoyLjQ3LjAKCg== --b1=_ZGwg7xAQGhHY2uGzYs1KbVimueoWtxvfqMEkzW0xdw-- From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 24 10:12:56 2024 Received: (at 73985) by debbugs.gnu.org; 24 Oct 2024 14:12:56 +0000 Received: from localhost ([127.0.0.1]:35803 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3ya8-0006A5-8s for submit@debbugs.gnu.org; Thu, 24 Oct 2024 10:12:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3ya6-00069o-MM for 73985@debbugs.gnu.org; Thu, 24 Oct 2024 10:12:55 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3yZU-0005E2-Vi; Thu, 24 Oct 2024 10:12:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=oL/w3KSwNP60chTvyqxX7ooyFC91aISBrW7n8RLuTuI=; b=l8E7X9gGsBE/ WgBI/KDqSZSzI5A4rYM7rxiqaRf/VZR/MmJW1RYBxScYnr2GMiwP7WVJeN7RWx8qix6uHLjXMG7mx nG400N5B/A3y0g1EQOTfh0dQR1JIaIUl7jenLn237wKBZEUgDG+t76yTp6rKiXUhqdg8Px7p14NhZ nAd1c+DjhLa8ip9GGpLLc3YvVkyQINTEyHYZNi1xI/N23UULXxmjdzER3d9ATlZB7iKc3OM5j+p4S dUN9cWV9+Dlqoz/Vo2eFomogZwMm5TKhnyAjSufHN0flvO1RAjrRpDXTNiZ6eY+e/tvnWnObgaa2V QnTkzy51ImK2njrHPPW11g==; Date: Thu, 24 Oct 2024 17:12:13 +0300 Message-Id: <86plnpd1z6.fsf@gnu.org> From: Eli Zaretskii To: altermo31 In-Reply-To: (bug-gnu-emacs@gnu.org) Subject: Re: bug#73985: fix: charset.max_char may be used before being set References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73985 Cc: 73985@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Thu, 24 Oct 2024 11:46:17 +0000 > From: altermo31 via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > Problem: > If the value to be set to charset.max_char is invalid, an error occurs, but the error uses the yet unset charset.max_char. > > Solution: > Use the value that charset.max_char would be set to if the value wasn't invalid. Thanks. You are right that the original code is incorrect, but the code you propose has a subtle problem: the sum i + charset.code_offset could overflow. So we need to find a safer way of explaining the problem. From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 24 10:43:24 2024 Received: (at 73985) by debbugs.gnu.org; 24 Oct 2024 14:43:24 +0000 Received: from localhost ([127.0.0.1]:35855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3z3b-0007af-Nd for submit@debbugs.gnu.org; Thu, 24 Oct 2024 10:43:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3z3V-0007aL-9w for 73985@debbugs.gnu.org; Thu, 24 Oct 2024 10:43:21 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3z2u-0001yE-3P; Thu, 24 Oct 2024 10:42:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=d5ZyaR6nr6rSvuSEnGgo7rCmBgVCJmE4AMYzraKemcY=; b=calp/HTKTR3J k2F6uSvCqXcfQWmMWKQJ7I0RGr1ftZntvgcH9nHl3cm0vs8Vqx8QRBLdPafQW9YFWDbzYL8uV3oQg U0WhOD7gofPAURo+8Z8iF8rDl9rF4kRBkHCo19xitrcQC49SqPG3XmQ/kR2eOOKOTEuZQSjy8Ry8g uOfPkmQhN8Yhqc8zGgGaSC2hTznmUpo55sm/0UAzkF74Z4cJ7WGt2WpmbM0d6zrKcGrXlSxG3JoLn LBPy3lIqLHjepKdIQAVB98ChV5Zy+EmntjQ0dYluco+WqsefsC854uwF3C/QJwzCXbPLMn1Rvxi0K fSjbyzNoJDASGBdrcZMh0A==; Date: Thu, 24 Oct 2024 17:42:36 +0300 Message-Id: <86ldydd0kj.fsf@gnu.org> From: Eli Zaretskii To: altermo31@proton.me In-Reply-To: <86plnpd1z6.fsf@gnu.org> (message from Eli Zaretskii on Thu, 24 Oct 2024 17:12:13 +0300) Subject: Re: bug#73985: fix: charset.max_char may be used before being set References: <86plnpd1z6.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73985 Cc: 73985@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 73985@debbugs.gnu.org > Date: Thu, 24 Oct 2024 17:12:13 +0300 > From: Eli Zaretskii > > > Date: Thu, 24 Oct 2024 11:46:17 +0000 > > From: altermo31 via "Bug reports for GNU Emacs, > > the Swiss army knife of text editors" > > > > Problem: > > If the value to be set to charset.max_char is invalid, an error occurs, but the error uses the yet unset charset.max_char. > > > > Solution: > > Use the value that charset.max_char would be set to if the value wasn't invalid. > > Thanks. You are right that the original code is incorrect, but the > code you propose has a subtle problem: the sum > > i + charset.code_offset > > could overflow. So we need to find a safer way of explaining the > problem. I fixed that (on the master branch) like this: diff --git a/src/charset.c b/src/charset.c index e8d0826..f7d80cc 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1007,7 +1007,8 @@ DEFUN ("define-charset-internal", Fdefine_charset_internal, i = CODE_POINT_TO_INDEX (&charset, charset.max_code); if (MAX_CHAR - charset.code_offset < i) - error ("Unsupported max char: %d", charset.max_char); + error ("Unsupported max char: %d + %ud > MAX_CHAR (%d)", + i, charset.max_code, MAX_CHAR); charset.max_char = i + charset.code_offset; i = CODE_POINT_TO_INDEX (&charset, charset.min_code); charset.min_char = i + charset.code_offset; From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 09 04:12:35 2024 Received: (at 73985-done) by debbugs.gnu.org; 9 Nov 2024 09:12:35 +0000 Received: from localhost ([127.0.0.1]:53395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9hWF-0001Lx-FW for submit@debbugs.gnu.org; Sat, 09 Nov 2024 04:12:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56086) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9hWA-0001Lg-NR for 73985-done@debbugs.gnu.org; Sat, 09 Nov 2024 04:12:34 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9hW5-0001W1-2e; Sat, 09 Nov 2024 04:12:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=a7H4fchAb+R9EvI92HY7SYq1Sz5l4PraRX7MSlytGLg=; b=B0jSbXmtBXcF lV1s4kHblO473Tpv4i2OBESAJNQvUAAtZubmtvH8cAtRvgrUwruL2kmTjKF9TUu9dGjH4B2Rt9MgN XHg7B5fB12dnfafIH9Vzlh+W4TEpflYhncpzsF1f6ESIJ9aE9JF17oeNG7spEih+RWigRkntydl72 CWVr+zlj4txBQk7Ed9p6Sm5ofcYHybj8nfKDAeNsNgTOcowcdDYioK8yfczFwji67EyNPWx3nGDi1 JdvTcZP1nfvxQolbvX7cX+UV9qYrZ8mmM4V3fe8dM8syJ2xvioEYPhKzgPa9dGhqYkzWyJDslMgra ZNJoYXqZmTtFSN0TsWSAJg==; Date: Sat, 09 Nov 2024 11:12:22 +0200 Message-Id: <861pzkojnt.fsf@gnu.org> From: Eli Zaretskii To: altermo31@proton.me In-Reply-To: <86ldydd0kj.fsf@gnu.org> (message from Eli Zaretskii on Thu, 24 Oct 2024 17:42:36 +0300) Subject: Re: bug#73985: fix: charset.max_char may be used before being set References: <86plnpd1z6.fsf@gnu.org> <86ldydd0kj.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73985-done Cc: 73985-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 73985@debbugs.gnu.org > Date: Thu, 24 Oct 2024 17:42:36 +0300 > From: Eli Zaretskii > > > Thanks. You are right that the original code is incorrect, but the > > code you propose has a subtle problem: the sum > > > > i + charset.code_offset > > > > could overflow. So we need to find a safer way of explaining the > > problem. > > I fixed that (on the master branch) like this: > > diff --git a/src/charset.c b/src/charset.c > index e8d0826..f7d80cc 100644 > --- a/src/charset.c > +++ b/src/charset.c > @@ -1007,7 +1007,8 @@ DEFUN ("define-charset-internal", Fdefine_charset_internal, > > i = CODE_POINT_TO_INDEX (&charset, charset.max_code); > if (MAX_CHAR - charset.code_offset < i) > - error ("Unsupported max char: %d", charset.max_char); > + error ("Unsupported max char: %d + %ud > MAX_CHAR (%d)", > + i, charset.max_code, MAX_CHAR); > charset.max_char = i + charset.code_offset; > i = CODE_POINT_TO_INDEX (&charset, charset.min_code); > charset.min_char = i + charset.code_offset; No further comments, so I'm now closing this bug. From unknown Thu Aug 14 12:22:14 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 07 Dec 2024 12:24:13 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator