check for wrapping to negative in hash lookup of cell (issue #735)

Without this chibi can crash after 129 open file descriptors.

Note the bug referenced would also indirectly be fixed if
process->string-list properly closed its ports, but we
shouldn't rely on that.
This commit is contained in:
Alex Shinn 2021-03-31 06:43:27 +09:00
parent 13a2a562d9
commit 7ea15f3810

4
sexp.c
View file

@ -1809,7 +1809,9 @@ static sexp* sexp_fileno_cell(sexp ctx, sexp vec, int fd) {
if (len == 0)
return NULL;
data = sexp_vector_data(vec);
for (i = 0, cell = (fd * FNV_PRIME) % len; i < len; i++, cell=(cell+1)%len)
cell = (fd * FNV_PRIME) % len;
if (cell < 0) cell += len;
for (i = 0; i < len; i++, cell=(cell+1)%len)
if (!sexp_ephemeronp(data[cell])
|| (sexp_filenop(sexp_ephemeron_key(data[cell]))
&& sexp_fileno_fd(sexp_ephemeron_key(data[cell])) == fd))