* bug#73985: fix: charset.max_char may be used before being set
@ 2024-10-24 11:46 altermo31 via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 14:12 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: altermo31 via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-24 11:46 UTC (permalink / raw)
To: 73985
[-- Attachment #1: Type: text/plain, Size: 227 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fix-charset.max_char-may-be-used-before-being-set.patch --]
[-- Type: text/x-patch; name=0001-fix-charset.max_char-may-be-used-before-being-set.patch, Size: 910 bytes --]
From 64e9557c5f6ae4416a1a12fd6f68f0d19931bb99 Mon Sep 17 00:00:00 2001
From: altermo <107814000+altermo@users.noreply.github.com>
Date: Thu, 24 Oct 2024 13:39:06 +0200
Subject: [PATCH] fix: charset.max_char may be used before being set
---
src/charset.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/charset.c b/src/charset.c
index e8d0826..14b33d2 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1007,7 +1007,7 @@ 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", i + charset.code_offset);
charset.max_char = i + charset.code_offset;
i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
charset.min_char = i + charset.code_offset;
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#73985: fix: charset.max_char may be used before being set
2024-10-24 11:46 bug#73985: fix: charset.max_char may be used before being set altermo31 via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-24 14:12 ` Eli Zaretskii
2024-10-24 14:42 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2024-10-24 14:12 UTC (permalink / raw)
To: altermo31; +Cc: 73985
> Date: Thu, 24 Oct 2024 11:46:17 +0000
> From: altermo31 via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#73985: fix: charset.max_char may be used before being set
2024-10-24 14:12 ` Eli Zaretskii
@ 2024-10-24 14:42 ` Eli Zaretskii
0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2024-10-24 14:42 UTC (permalink / raw)
To: altermo31; +Cc: 73985
> Cc: 73985@debbugs.gnu.org
> Date: Thu, 24 Oct 2024 17:12:13 +0300
> From: Eli Zaretskii <eliz@gnu.org>
>
> > Date: Thu, 24 Oct 2024 11:46:17 +0000
> > From: altermo31 via "Bug reports for GNU Emacs,
> > the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> >
> > 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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-24 14:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24 11:46 bug#73985: fix: charset.max_char may be used before being set altermo31 via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-24 14:12 ` Eli Zaretskii
2024-10-24 14:42 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).