Skip to content

Commit ee70eb0

Browse files
JohnoKingMcDutchie
andcommitted
Sundrous fixes (#862)
- align.c: Remove null pointer arithmetic. - man pages: Fix mandoc warnings pertaining to lines exceeding 80 bytes. - Increase the SEARCHSIZE and LOOKAHEAD definitions from 80 to 500. (vide #460 (comment)) - tminit(): Fixed a small memory leak ASan was complaining about. - Replaced alignof macro in nvtype.c by a version from Martijn that uses offsetof instead of an outdated hack with null pointer dereferences, fixing the following UBSan error: runtime error: member access within null pointer of type '_Align_' - Fixed a compiler error that broke SHOPT_KIA by including shlex.h in defs.c. - Added pragmas to ignore some superfluous compiler warnings. - Added undefs to fix compiler warnings on illumos. - Amended the ASan test to check the binary (in case no ASAN_OPTIONS flag is present). Also apply a modified form of that test to another regression test incompatible with ASan and profiling. Co-authored-by: Martijn Dekker <martijn@inlv.org>
1 parent 1632949 commit ee70eb0

File tree

21 files changed

+547
-304
lines changed

21 files changed

+547
-304
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ This documents significant changes in the 1.0 branch of ksh 93u+m.
22
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
33
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
44

5+
2025-07-30:
6+
7+
- The editor typeahead buffer and the limit for the ${.sh.edchar} variable
8+
(used with the KEYBD trap) has been increased from 80 to 500 bytes.
9+
510
2025-07-29:
611

712
- Fixed a serious but rarely occurring regression that corrupts variable

src/cmd/ksh93/Mamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ make install virtual
586586
make sh/defs.c
587587
prev include/jobs.h
588588
prev include/defs.h
589+
prev include/shlex.h
589590
prev shopt.h
590591
done
591592

src/cmd/ksh93/include/edit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
*
2626
*/
2727

28-
#define SEARCHSIZE 80
28+
#define SEARCHSIZE 500
2929

3030
#include "FEATURE/cmds"
3131
#include "FEATURE/locale"
3232
#include "terminal.h"
3333

3434
#define STRIP 0377
35-
#define LOOKAHEAD 80
35+
#define LOOKAHEAD 500
3636

3737
#if SHOPT_MULTIBYTE
3838
# include "national.h"

src/cmd/ksh93/include/shtable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* This software is part of the ast package *
44
* Copyright (c) 1982-2012 AT&T Intellectual Property *
5-
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
5+
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
66
* and is licensed under the *
77
* Eclipse Public License, Version 2.0 *
88
* *
@@ -60,4 +60,4 @@ extern const Shtable_t *sh_locate(const char*, const Shtable_t*, int);
6060
extern int sh_lookopt(const char*, int*);
6161
extern Dt_t *sh_inittree(const struct shtable2*);
6262

63-
#endif /* SH_TABLE_H */
63+
#endif /* _SHTABLE_H */

src/cmd/ksh93/sh.1

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,8 @@ The first (default: \f3!\fP) signals the start of a history expansion.
20822082
The second (default: \f3^\fP) is used for short-form substitutions.
20832083
The third (default: \f3#\fP), when found as the first character of a word,
20842084
causes history expansion to be skipped for the rest of the words on the line.
2085-
Multi-byte characters (e.g. UTF-8) are not supported and produce undefined results.
2085+
Multi-byte characters (e.g. UTF-8) are not supported and produce
2086+
undefined results.
20862087
.TP
20872088
.B
20882089
.SM HISTCMD
@@ -4734,8 +4735,10 @@ Normally, this means that a command line with an erroneous history expansion
47344735
is lost and needs to be retyped from scratch,
47354736
but if the \f3histreedit\fP shell option is turned on
47364737
and a line editor is active (see \f2In-line Editing Options\fP below),
4737-
the erroneous line is pre-filled into the next prompt's input buffer for correcting.
4738-
The \f3histverify\fP option causes the same to be done for the results of successful
4738+
the erroneous line is pre-filled into the next prompt's input buffer
4739+
for correcting.
4740+
The \f3histverify\fP option causes the same to be done for the results
4741+
of successful
47394742
history expansions, allowing verification and editing before execution.
47404743
.PP
47414744
A history expansion may have an \f2event specification\fP, which indicates
@@ -4783,12 +4786,14 @@ output by the \f3hist -l\fP command:
47834786
The commands are shown with their event numbers.
47844787
The current event, which we haven't typed in yet, is event 13.
47854788
\f3!11\fP and \f3!\-2\fP refer to event 11.
4786-
\f3!!\fP refers to the previous event, 12. \f3!!\fP can be abbreviated \f3!\fP if it is
4789+
\f3!!\fP refers to the previous event, 12. \f3!!\fP can be
4790+
abbreviated \f3!\fP if it is
47874791
followed by \f3:\fP (see below).
47884792
\f3!n\fP refers to event 9, which begins with \f3n\fP.
47894793
\f3!?old?\fP also refers to event 12, which contains \f3old\fP.
4790-
Without word designators or modifiers, history references simply expand to the
4791-
entire event, so we might type \f3!cp\fP to redo the copy command or \f3!!|more\fP
4794+
Without word designators or modifiers, history references simply
4795+
expand to the entire event, so we might type \f3!cp\fP to redo the
4796+
copy command or \f3!!|more\fP
47924797
if the \f3diff\fP output scrolled off the top of the screen.
47934798
.PP
47944799
To select words from an event,
@@ -4842,16 +4847,17 @@ arguments from the \f3cp\fP command. If we didn't care about the order of the
48424847
\f3diff\fP, we might have said \f3diff !\-2:1\-2\fP or simply \f3diff !\-2:*\fP.
48434848
The \f3cp\fP command might have been written \f3cp wumpus.man !#:1.old\fP,
48444849
using \f3#\fP to refer to the current event.
4845-
\f3!n:\- hurkle.man\fP would reuse the first two words from the \f3nroff\fP command
4846-
to say \f3nroff \-man hurkle.man\fP.
4850+
\f3!n:\- hurkle.man\fP would reuse the first two words from
4851+
the \f3nroff\fP command to say \f3nroff \-man hurkle.man\fP.
48474852
.PP
48484853
The \f3:\fP separating the event specification from the word designator
48494854
can be omitted if the argument selector begins with a
48504855
\f3^\fP, \f3$\fP, \f3*\fP, \f3%\fP or \f3\-\fP.
48514856
For example, our \f3diff\fP command might have been \f3diff !!^.old !!^\fP
48524857
or, equivalently, \f3diff !!$.old !!$\fP.
48534858
However, if \f3!!\fP is abbreviated \f3!\fP,
4854-
an argument selector beginning with \f3\-\fP will be interpreted as an event specification.
4859+
an argument selector beginning with \f3\-\fP will be interpreted
4860+
as an event specification.
48554861
.PP
48564862
The word(s) in a history reference can be edited
48574863
by following them with one or more modifiers,
@@ -4886,7 +4892,8 @@ If \f2l\fP is empty,
48864892
the \f2l\fP from the previous substitution is used,
48874893
or if there is none,
48884894
the \f2s\fP from the most recent \f3?\fP\f2s\fP\f3?\fP search.
4889-
The trailing delimiter may be omitted if it is immediately followed by a newline.
4895+
The trailing delimiter may be omitted if it is immediately followed
4896+
by a newline.
48904897
.TP 8
48914898
.B &
48924899
Repeat the previous substitution.
@@ -4921,16 +4928,19 @@ We might follow \f3mail \-s "I forgot my password" rot\fP
49214928
with \f3!:s/rot/root\fP to correct the spelling of \f3root\fP.
49224929
.PP
49234930
History expansions also occur when an input line begins with \f3^\fP.
4924-
When it is the first character on an input line, it is an abbreviation of \f3!:s^\fP.
4925-
Thus we might have said \f3^rot^root\fP to make the spelling correction in the previous example.
4931+
When it is the first character on an input line,
4932+
it is an abbreviation of \f3!:s^\fP.
4933+
Thus we might have said \f3^rot^root\fP to make the spelling correction
4934+
in the previous example.
49264935
This is the only history expansion that does not explicitly begin with \f3!\fP.
49274936
.PP
49284937
If a word on a command line begins with the history comment character \f3#\fP,
49294938
history expansion is ignored for the rest of that line.
49304939
This usually causes the shell parser
49314940
(which uses the same character to signal a comment)
49324941
to treat the rest of the line as a comment as well,
4933-
but as history expansion is parsed separately from the shell grammar and with different rules,
4942+
but as history expansion is parsed separately from the shell grammar
4943+
and with different rules,
49344944
this cannot be guaranteed in all cases.
49354945
If the history comment character is changed,
49364946
the shell grammar comment character does not change along with it.
@@ -6310,9 +6320,11 @@ is given, the name
63106320
and value of the alias is printed.
63116321
The obsolete
63126322
.B \-x
6313-
option has no effect in most contexts, although if it's used with
6323+
option has no effect in most contexts, but when it's used with
63146324
.B \-t
6315-
it will suppress all output.
6325+
it will cause
6326+
.B alias
6327+
to do nothing.
63166328
The exit status is non-zero if a
63176329
.I name\^
63186330
is given, but no value, and no alias has been defined for the

src/cmd/ksh93/sh/defs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "shopt.h"
2525
#include "defs.h"
2626
#include "jobs.h"
27+
#include "shlex.h"
2728

2829
Shell_t sh = {0};
2930

src/cmd/ksh93/sh/nvtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef struct
115115
char *_dpointer;
116116
} _Align_;
117117

118-
#define alignof(t) ((char*)&((_Align_*)0)->_d##t-(char*)&((_Align_*)0)->_c##t)
118+
#define alignof(t) ( offsetof(_Align_, _d##t) - offsetof(_Align_, _c##t) )
119119

120120
static void put_type(Namval_t*, const char*, int, Namfun_t*);
121121
static Namval_t* create_type(Namval_t*, const char*, int, Namfun_t*);

src/cmd/ksh93/tests/basic.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -693,19 +693,28 @@ getCmdline() {
693693
getPsOutput "$1"
694694
fi
695695
}
696-
if [[ ! $(uname -s) =~ ^SunOS$ ]] &&
697-
getPsOutput "$$" &&
698-
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
699-
then expect='./atest 1 2'
700-
echo 'sleep 10; exit 0' >atest
701-
chmod 755 atest
702-
./atest 1 2 &
703-
getCmdline "$!"
704-
kill "$!"
705-
[[ $actual == "$expect" ]] || err_exit "ksh didn't rewrite argv correctly" \
706-
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
696+
check_profiling_or_asan() {
697+
# Skip test when the binary was compiled with ASAN or is gathering profiling data
698+
[[ -v ASAN_OPTIONS || -v TSAN_OPTIONS || -v MSAN_OPTIONS || -v LSAN_OPTIONS ]] && return 0
699+
! whence -q readelf && return 1
700+
[[ -n $(readelf -s "$SHELL" | grep -E "_asan_|__gcov") ]] && return 0
701+
return 1
702+
}
703+
if ! check_profiling_or_asan
704+
then if [[ ! $(uname -s) =~ ^SunOS$ ]] &&
705+
getPsOutput "$$" &&
706+
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
707+
then expect='./atest 1 2'
708+
echo 'sleep 10; exit 0' >atest
709+
chmod 755 atest
710+
./atest 1 2 &
711+
getCmdline "$!"
712+
kill "$!"
713+
[[ $actual == "$expect" ]] || err_exit "ksh didn't rewrite argv correctly" \
714+
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
715+
fi
716+
unset -f getPsOutput getCmdline
707717
fi
708-
unset -f getPsOutput getCmdline
709718
710719
# ======
711720
# https://bugzilla.redhat.com/1241013

src/cmd/ksh93/tests/signal.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,14 @@ yes() for ((;;)); do print y; done
397397
# The test for SIGBUS trap handling below is incompatible with ASan because ASan
398398
# implements its own SIGBUS handler independently of ksh.
399399
# Also, Android does not allow ignoring SIGBUS.
400-
if ! [[ -v ASAN_OPTIONS || -v TSAN_OPTIONS || -v MSAN_OPTIONS || -v LSAN_OPTIONS || $HOSTTYPE == android.* ]]; then
400+
check_asan() {
401+
# Skip test when the binary was compiled with ASAN or is gathering profiling data
402+
[[ -v ASAN_OPTIONS || -v TSAN_OPTIONS || -v MSAN_OPTIONS || -v LSAN_OPTIONS ]] && return 0
403+
! whence -q readelf && return 1
404+
[[ -n $(readelf -s "$SHELL" | grep -E "_asan_") ]] && return 0
405+
return 1
406+
}
407+
if ! check_asan && ! [[ $HOSTTYPE == android.* ]]; then
401408
trap '' SIGBUS
402409
got=$("$SHELL" -c 'trap date SIGBUS; trap -p SIGBUS')
403410
[[ "$got" ]] && err_exit 'SIGBUS should not have a trap' \

src/lib/libast/features/align.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ main(void)
110110
printf("\n");
111111
printf("#define ALIGN_CHUNK %d\n", sizeof(char*) >= 4 ? 8192 : 1024);
112112
printf("#define ALIGN_INTEGRAL uintptr_t\n");
113-
printf("#define ALIGN_INTEGER(x) ((char*)(x)-(char*)0)\n");
113+
printf("#define ALIGN_INTEGER(x) ((intptr_t)(x))\n");
114114
printf("#define ALIGN_POINTER(x) ((char*)(x))\n");
115115
if (bits2 == (align2 - 1))
116116
printf("#define ALIGN_ROUND(x,y) ALIGN_POINTER(ALIGN_INTEGER((x)+(y)-1)&~((y)-1))\n");

0 commit comments

Comments
 (0)