[PATCH v9 6/9] ell/term: Return error on writes if the output descriptor is invalid.
Grant Erickson <[email protected]> Sun, 6 Apr 2025 15:06:02 -0700
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <7de7f13c49042a0e09fe9760055c81787b3aee4b.1743976923.git.gerickson@nuovations.com> |
Returns -EBADF for 'putnstr' and 'vdprintf' if the output descriptor for the terminal is invalid. --- ell/term.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ell/term.c b/ell/term.c index c867b240090c..7ec92476e14e 100644 --- a/ell/term.c +++ b/ell/term.c @@ -391,6 +391,9 @@ LIB_EXPORT int l_term_putnstr(struct l_term *term, const char *str, size_t n) if (!term) return -EINVAL; + if (term->out_fd < 0) + return -EBADF; + res = write(term->out_fd, str, n); if (res < 0) return -errno; @@ -432,6 +435,9 @@ LIB_EXPORT int l_term_vprint(struct l_term *term, const char *str, va_list ap) if (!term || !str) return -EINVAL; + if (term->out_fd < 0) + return -EBADF; + if (vdprintf(term->out_fd, str, ap) < 0) return -errno; -- 2.45.0