diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-19 18:28:39 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-19 18:28:39 +0300 |
commit | afdb2acdecf4b563ed037f983b820ce82f6735ba (patch) | |
tree | 931a932367bf700d7e53fefdbe07605ae1afb4f5 | |
parent | 29e11f68bae0364034fb692062403735bec8d07a (diff) | |
download | sciteco-afdb2acdecf4b563ed037f983b820ce82f6735ba.tar.gz |
fixed <EF> and <EW> with invalid buffer ids (was crashing)
* regression introduced in 2baa14add6d9976c29b27cf4470bb458a0198694
-rw-r--r-- | src/error.h | 8 | ||||
-rw-r--r-- | src/ring.c | 11 | ||||
-rw-r--r-- | tests/testsuite.at | 6 |
3 files changed, 23 insertions, 2 deletions
diff --git a/src/error.h b/src/error.h index 61bcce6..04bb988 100644 --- a/src/error.h +++ b/src/error.h @@ -47,6 +47,7 @@ typedef enum { TECO_ERROR_WORDS, TECO_ERROR_RANGE, TECO_ERROR_SUBPATTERN, + TECO_ERROR_INVALIDBUF, TECO_ERROR_INVALIDQREG, TECO_ERROR_QREGOPUNSUPPORTED, TECO_ERROR_QREGCONTAINSNULL, @@ -126,6 +127,13 @@ teco_error_subpattern_set(GError **error, const gchar *cmd) } static inline void +teco_error_invalidbuf_set(GError **error, teco_int_t id) +{ + g_set_error(error, TECO_ERROR, TECO_ERROR_INVALIDBUF, + "Invalid buffer id %" TECO_INT_FORMAT, id); +} + +static inline void teco_error_invalidqreg_set(GError **error, const gchar *name, gsize len, gboolean local) { g_autofree gchar *name_printable = teco_string_echo(name, len); @@ -305,8 +305,7 @@ teco_ring_edit_by_id(teco_int_t id, GError **error) { teco_buffer_t *buffer = teco_ring_find(id); if (!buffer) { - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Invalid buffer id %" TECO_INT_FORMAT, id); + teco_error_invalidbuf_set(error, id); return FALSE; } @@ -557,6 +556,10 @@ teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE if (!teco_expressions_pop_num_calc(&id, 0, error)) return NULL; buffer = teco_ring_find(id); + if (!buffer) { + teco_error_invalidbuf_set(error, id); + return NULL; + } } else if (teco_qreg_current) { return !teco_qreg_current->vtable->save(teco_qreg_current, filename, error) ? NULL : &teco_state_start; @@ -688,6 +691,10 @@ teco_state_ecommand_close(teco_machine_main_t *ctx, GError **error) if (!teco_expressions_pop_num_calc(&id, 0, error)) return; buffer = teco_ring_find(ABS(id)); + if (!buffer) { + teco_error_invalidbuf_set(error, ABS(id)); + return; + } force = id < 0; } else if (teco_qreg_current) { /* diff --git a/tests/testsuite.at b/tests/testsuite.at index 44d90bd..034427f 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -391,6 +391,12 @@ AT_SETUP([Search accesses wrong Q-Register table]) TE_CHECK([[@^U.#xx/123/ @^Um{:@S/^EG.#xx/$} :Mm Mm]], 1, ignore, ignore) AT_CLEANUP +AT_SETUP([Invalid buffer ids]) +TE_CHECK([[42@EB//]], 1, ignore, ignore) +TE_CHECK([[23@EW//]], 1, ignore, ignore) +TE_CHECK([[11EF]], 1, ignore, ignore) +AT_CLEANUP + AT_SETUP([Memory limiting during spawning]) # This might result in an OOM if memory limiting is not working TE_CHECK([[50*1000*1000,2EJ 0,128ED @EC'dd if=/dev/zero']], 1, ignore, ignore) |