Re: [hackers] [sbase][PATCH] libutil/random: better random seed

2024-03-05 Thread NRK
> - *state = ts.tv_nsec; > + *state = (intptr_t) ^ time(NULL) ^ (ts.tv_nsec * 0xAC5533CD); tv_nsec is `long` which is signed. Signed interger overflow is undefined. You need to cast it to `unsigned long` before multiply: ... ^ ((unsigned long)ts.tv_nsec * 0xAC5533CD) - NRK

Re: [hackers] [sbase][PATCH] libutil/random: better random seed

2024-03-05 Thread Steve Ward
On Mon, Mar 4, 2024 at 5:03 PM Elie Le Vaillant wrote: > > Thanks NRK > --- > libutil/random.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/libutil/random.c b/libutil/random.c > index 780ba29..6b795a9 100644 > --- a/libutil/random.c > +++ b/libutil/random.c > @@

Re: [hackers] [sbase][PATCH] head: remove useless buffering

2024-03-05 Thread NRK
> + while (i < n && (c = fgetc(fp)) != EOF) { > + if (fputc(c, stdout) == EOF) I don't see this as an improvement. Each one of the fgetc and fputc are going to go through a mutex lock (along with possibly going through a call into a dynamic function). I think the current solution

[hackers] [sbase][PATCH] tar: chktar: fix conditional typo

2024-03-05 Thread Elie Le Vaillant
--- tar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tar.c b/tar.c index 0361b63..405b8d9 100644 --- a/tar.c +++ b/tar.c @@ -423,7 +423,7 @@ chktar(struct header *h) goto bad; } memcpy(tmp, h->chksum, sizeof(tmp)); - for (i = 0; i <

Re: [hackers] [sbase][PATCH] Add implementation of tac(1)

2024-03-05 Thread Eric Pruitt
On Sun, Mar 03, 2024 at 12:34:16AM +0100, Elie Le Vaillant wrote: > +static void > +tac(FILE *fp) > +{ > + struct linebuf buf = EMPTY_LINEBUF; > + struct line line; > + getlines(fp, ); > + > + if (buf.nolf) { > + /* If the last line is not LF-terminated, the > +

[hackers] [sbase][PATCH] head: remove useless buffering

2024-03-05 Thread Elie Le Vaillant
getline isn't useful here, because we just need to read then output lines. We do not need anything more complex than counting '\n's, so we shouldn't use a buffer like we currently do. --- head.c | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/head.c b/head.c

[hackers] [sbase][PATCH] libutil/random: no need to call time() when we have timespec

2024-03-05 Thread Elie Le Vaillant
Thanks Steve Ward --- libutil/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libutil/random.c b/libutil/random.c index 6b795a9..d5214ae 100644 --- a/libutil/random.c +++ b/libutil/random.c @@ -67,7 +67,7 @@ rng32_seed_r(uint64_t *state) { struct timespec ts;

Re: [hackers] [sbase][PATCH v3] tar: sanitize, chktar: leading spaces should be skipped over

2024-03-05 Thread Roberto E. Vargas Caballero
Hi, On Sun, Feb 11, 2024 at 09:26:14AM +0100, Elie Le Vaillant wrote: > Some tar archives (eg. ftp://ftp.gnu.org/gnu/shtool/shtool-2.0.8.tar.gz) > use leading spaces instead of leading zeroes for numeric fields. > Although it is not allowed by the ustar specification, most tar > implementations

[hackers] [sbase] tar: sanitize, chktar: leading spaces should be skipped over || Elie Le Vaillant

2024-03-05 Thread git
commit bca3fcca91cfb6ee64434776aa20209547816c17 Author: Elie Le Vaillant AuthorDate: Sun Feb 11 09:26:14 2024 +0100 Commit: Roberto E. Vargas Caballero CommitDate: Tue Mar 5 13:25:44 2024 +0100 tar: sanitize, chktar: leading spaces should be skipped over Some tar archives

Re: [hackers] [sbase][PATCH v2] tar: sanitize: leading zeros should be recognized

2024-03-05 Thread Roberto E. Vargas Caballero
On Tue, Mar 05, 2024 at 01:16:36PM +0100, Roberto E. Vargas Caballero wrote: > Hi, > > On Sat, Feb 10, 2024 at 11:57:38PM +0100, Elie Le Vaillant wrote: > > @@ -399,10 +400,17 @@ sanitize(struct header *h) > > for (i = 0; i < LEN(fields); i++) > > - for (j = 0; j < fields[i].l; j++)

Re: [hackers] [sbase][PATCH v2] tar: sanitize: leading zeros should be recognized

2024-03-05 Thread Roberto E. Vargas Caballero
Hi, On Sat, Feb 10, 2024 at 11:57:38PM +0100, Elie Le Vaillant wrote: > @@ -399,10 +400,17 @@ sanitize(struct header *h) > for (i = 0; i < LEN(fields); i++) > - for (j = 0; j < fields[i].l; j++) > + for (leading = 1, j = 0; j < fields[i].l; j++) >