Skip to content

Commit

Permalink
import freebsd 14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
q66 committed Dec 3, 2024
1 parent 0712360 commit 4ec3b9f
Show file tree
Hide file tree
Showing 43 changed files with 423 additions and 279 deletions.
159 changes: 82 additions & 77 deletions patches/src.freebsd.patch

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src.freebsd/awk/FIXES
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the
second edition of the AWK book was published in September 2023.

Apr 22, 2024:
fixed regex engine gototab reallocation issue that was
introduced during the Nov 24 rewrite. Thanks to Arnold Robbins.
Fixed a scan bug in split in the case the separator is a single
character. thanks to Oguz Ismail for spotting the issue.

Mar 10, 2024:
fixed use-after-free bug in fnematch due to adjbuf invalidating
the pointers to buf. thanks to github user caffe3 for spotting
the issue and providing a fix, and to Miguel Pineiro Jr.
for the alternative fix.
MAX_UTF_BYTES in fnematch has been replaced with awk_mb_cur_max.
thanks to Miguel Pineiro Jr.

Jan 22, 2024:
Restore the ability to compile with g++. Thanks to
Arnold Robbins.
Expand Down
2 changes: 1 addition & 1 deletion src.freebsd/awk/awk.1
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ to it.
The scope rules for variables in functions are a botch;
the syntax is worse.
.Sh DEPRECATED BEHAVIOR
One True Awk has accpeted
One True Awk has accepted
.Fl F Ar t
to mean the same as
.Fl F Ar <TAB>
Expand Down
34 changes: 20 additions & 14 deletions src.freebsd/awk/b.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab implem
if (tab->inuse + 1 >= tab->allocated)
resize_gototab(f, state);

f->gototab[state].entries[f->gototab[state].inuse-1].ch = ch;
f->gototab[state].entries[f->gototab[state].inuse-1].state = val;
f->gototab[state].entries[f->gototab[state].inuse].ch = ch;
f->gototab[state].entries[f->gototab[state].inuse].state = val;
f->gototab[state].inuse++;
return val;
} else {
Expand All @@ -677,9 +677,9 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab implem
gtt *tab = & f->gototab[state];
if (tab->inuse + 1 >= tab->allocated)
resize_gototab(f, state);
++tab->inuse;
f->gototab[state].entries[tab->inuse].ch = ch;
f->gototab[state].entries[tab->inuse].state = val;
++tab->inuse;

qsort(f->gototab[state].entries,
f->gototab[state].inuse, sizeof(gtte), entry_cmp);
Expand Down Expand Up @@ -830,8 +830,6 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
}


#define MAX_UTF_BYTES 4 // UTF-8 is up to 4 bytes long

/*
* NAME
* fnematch
Expand Down Expand Up @@ -868,16 +866,28 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)

do {
/*
* Call u8_rune with at least MAX_UTF_BYTES ahead in
* Call u8_rune with at least awk_mb_cur_max ahead in
* the buffer until EOF interferes.
*/
if (k - j < MAX_UTF_BYTES) {
if (k + MAX_UTF_BYTES > buf + bufsize) {
if ((k - j) < 0 || (size_t)(k - j) < awk_mb_cur_max) {
if (k + awk_mb_cur_max > buf + bufsize) {
char *obuf = buf;
adjbuf((char **) &buf, &bufsize,
bufsize + MAX_UTF_BYTES,
bufsize + awk_mb_cur_max,
quantum, 0, "fnematch");

/* buf resized, maybe moved. update pointers */
*pbufsize = bufsize;
if (obuf != buf) {
i = buf + (i - obuf);
j = buf + (j - obuf);
k = buf + (k - obuf);
*pbuf = buf;
if (patlen)
patbeg = buf + (patbeg - obuf);
}
}
for (n = MAX_UTF_BYTES ; n > 0; n--) {
for (n = awk_mb_cur_max ; n > 0; n--) {
*k++ = (c = getc(f)) != EOF ? c : 0;
if (c == EOF) {
if (ferror(f))
Expand Down Expand Up @@ -914,10 +924,6 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
s = 2;
} while (1);

/* adjbuf() may have relocated a resized buffer. Inform the world. */
*pbuf = buf;
*pbufsize = bufsize;

if (patlen) {
/*
* Under no circumstances is the last character fed to
Expand Down
2 changes: 1 addition & 1 deletion src.freebsd/awk/bugs-fixed/REGRESS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ do
then
rm -f $OUT
else
echo '++++ $i failed!'
echo "+++ $i failed!"
fi
done
3 changes: 3 additions & 0 deletions src.freebsd/awk/bugs-fixed/system-status.ok2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
normal status 42
death by signal status 257
death by signal with core dump status 262
2 changes: 1 addition & 1 deletion src.freebsd/awk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/

const char *version = "version 20240122";
const char *version = "version 20240422";

#define DEBUG
#include <stdio.h>
Expand Down
4 changes: 2 additions & 2 deletions src.freebsd/awk/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
for (;;) {
n++;
t = s;
while (*s != sep && *s != '\n' && *s != '\0')
while (*s != sep && *s != '\0')
s++;
temp = *s;
setptr(s, '\0');
Expand Down Expand Up @@ -2494,7 +2494,7 @@ void backsub(char **pb_ptr, const char **sptr_ptr);
Cell *dosub(Node **a, int subop) /* sub and gsub */
{
fa *pfa;
int tempstat;
int tempstat = 0;
char *repl;
Cell *x;

Expand Down
3 changes: 2 additions & 1 deletion src.freebsd/compress/zopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ getcode(struct s_zstate *zs)
}

/* High order bits. */
gcode |= (*bp & rmask[bits]) << r_off;
if (bits > 0)
gcode |= (*bp & rmask[bits]) << r_off;
roffset += n_bits;

return (gcode);
Expand Down
16 changes: 8 additions & 8 deletions src.freebsd/coreutils/cat/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ init_casper_net(cap_channel_t *casper)
familylimit = AF_LOCAL;
cap_net_limit_name2addr_family(limit, &familylimit, 1);

if (cap_net_limit(limit) < 0)
if (cap_net_limit(limit) != 0)
err(EXIT_FAILURE, "unable to apply limits");
}
#endif
Expand Down Expand Up @@ -219,15 +219,15 @@ main(int argc, char *argv[])
stdout_lock.l_start = 0;
stdout_lock.l_type = F_WRLCK;
stdout_lock.l_whence = SEEK_SET;
if (fcntl(STDOUT_FILENO, F_SETLKW, &stdout_lock) == -1)
if (fcntl(STDOUT_FILENO, F_SETLKW, &stdout_lock) != 0)
err(EXIT_FAILURE, "stdout");
}

init_casper(argc, argv);

caph_cache_catpages();

if (caph_enter_casper() < 0)
if (caph_enter_casper() != 0)
err(EXIT_FAILURE, "capsicum");

if (bflag || eflag || nflag || sflag || tflag || vflag)
Expand Down Expand Up @@ -287,7 +287,7 @@ scanfiles(char *argv[], int cooked __unused)
#endif
} else {
#ifndef BOOTSTRAP_CAT
if (in_kernel_copy(fd) == -1) {
if (in_kernel_copy(fd) != 0) {
if (errno == EINVAL || errno == EBADF ||
errno == EISDIR || errno == EXDEV ||
errno == ESPIPE || errno == ENOSYS)
Expand Down Expand Up @@ -516,7 +516,7 @@ udom_open(const char *path, int flags)
errno = serrno;
return (-1);
}
if (caph_rights_limit(fd, &rights) < 0) {
if (caph_rights_limit(fd, &rights) != 0) {
serrno = errno;
close(fd);
freeaddrinfo(res0);
Expand Down Expand Up @@ -545,20 +545,20 @@ udom_open(const char *path, int flags)
switch (flags & O_ACCMODE) {
case O_RDONLY:
cap_rights_clear(&rights, CAP_WRITE);
if (shutdown(fd, SHUT_WR) == -1)
if (shutdown(fd, SHUT_WR) != 0)
warn(NULL);
break;
case O_WRONLY:
cap_rights_clear(&rights, CAP_READ);
if (shutdown(fd, SHUT_RD) == -1)
if (shutdown(fd, SHUT_RD) != 0)
warn(NULL);
break;
default:
break;
}

cap_rights_clear(&rights, CAP_CONNECT, CAP_SHUTDOWN);
if (caph_rights_limit(fd, &rights) < 0) {
if (caph_rights_limit(fd, &rights) != 0) {
serrno = errno;
close(fd);
errno = serrno;
Expand Down
9 changes: 6 additions & 3 deletions src.freebsd/coreutils/date/date.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd May 2, 2024
.Dd September 10, 2024
.Dt DATE 1
.Os
.Sh NAME
Expand Down Expand Up @@ -538,8 +538,11 @@ Finally the command
.Pp
.Dl "TZ=America/Los_Angeles date -z Europe/Paris -j 0900"
.Pp
will print the time in the "Europe/Paris" timezone when it is 9:00 in The
America/Los_Angeles timezone.
will print the time in the
.Dq Europe/Paris
timezone when it is 9:00 in the
.Dq America/Los_Angeles
timezone.
.Sh DIAGNOSTICS
It is invalid to combine the
.Fl I
Expand Down
8 changes: 4 additions & 4 deletions src.freebsd/coreutils/date/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ strftime_ns(char * __restrict s, size_t maxsize, const char * __restrict format,
bool seen_percent;

seen_percent = false;
if (asprintf(&newformat, "%s", format) < 0)
err(1, "asprintf");
if ((newformat = strdup(format)) == NULL)
err(1, "strdup");
tok = newformat;
for (tok = newformat; *tok != '\0'; tok++) {
switch (*tok) {
Expand All @@ -425,9 +425,9 @@ strftime_ns(char * __restrict s, size_t maxsize, const char * __restrict format,
suffix = tok + 1;
/*
* Construct a new format string from the
* prefix (i.e., the part of the old fromat
* prefix (i.e., the part of the old format
* from its beginning to the currently handled
* "%N" conversion specification, the
* "%N" conversion specification), the
* nanoseconds, and the suffix (i.e., the part
* of the old format from the next token to the
* end).
Expand Down
41 changes: 31 additions & 10 deletions src.freebsd/coreutils/env/env.1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.\" From @(#)printenv.1 8.1 (Berkeley) 6/6/93
.\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp
.\"
.Dd March 3, 2021
.Dd October 8, 2024
.Dt ENV 1
.Os
.Sh NAME
Expand All @@ -43,6 +43,7 @@
.Op Ar name Ns = Ns Ar value ...
.Nm
.Op Fl iv
.Op Fl C Ar altwd
.Op Fl P Ar altpath
.Op Fl S Ar string
.Op Fl u Ar name
Expand Down Expand Up @@ -79,6 +80,12 @@ The environment inherited
by
.Nm
is ignored completely.
.\" -C
.It Fl C Ar altwd
Change to the specified alternate working directory before executing
the specified
.Ar utility
program.
.It Fl P Ar altpath
Search the set of directories as specified by
.Ar altpath
Expand Down Expand Up @@ -143,6 +150,19 @@ Both
and
.Ar utility
may not be specified together.
.Pp
The
.Nm
utility does not handle values of
.Ar utility
which have an equals sign
.Pq Ql =
in their name, for obvious reasons.
This can easily be worked around by interposing the
.Xr command 1
utility, which simply executes its arguments; see
.Sx EXAMPLES
below.
.\"
.Ss Details of -S (split-string) processing
The processing of the
Expand Down Expand Up @@ -441,6 +461,11 @@ and
options:
.Pp
.Dl "#!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl"
.Pp
To execute a utility with an equal sign in its name:
.Bd -literal -offset indent
env name=value ... command foo=bar arg ...
.Ed
.Sh COMPATIBILITY
The
.Nm
Expand All @@ -460,7 +485,7 @@ The
utility conforms to
.St -p1003.1-2001 .
The
.Fl 0 , L , P , S , U , u
.Fl 0 , C , L , P , S , U , u
and
.Fl v
options are non-standard extensions supported by
Expand All @@ -483,15 +508,11 @@ and
.Fl U
options were added in
.Fx 13.0 .
.Sh BUGS
The
.Nm
utility does not handle values of
.Ar utility
which have an equals sign
.Pq Ql =
in their name, for obvious reasons.
.Pp
.Fl C
option was added in
.Fx 14.2 .
.Sh BUGS
The
.Nm
utility does not take multibyte characters into account when
Expand Down
Loading

0 comments on commit 4ec3b9f

Please sign in to comment.