libsmartcols: make buffers append function more robust

Fixes: https://github.com/karelzak/util-linux/issues/1279
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-04-14 16:25:30 +02:00
parent 91f6895fff
commit aac716f503
1 changed files with 2 additions and 0 deletions

View File

@ -56,6 +56,8 @@ int buffer_append_data(struct libscols_buffer *buf, const char *str)
return -EINVAL;
if (!str || !*str)
return 0;
if (!buf->cur || !buf->begin)
return -EINVAL;
sz = strlen(str);
maxsz = buf->bufsz - (buf->cur - buf->begin);