forked from external/yambar
script: fix buffer resize bug
If the amount of data coming in is more than we can hold in our buffer, we resized the buffer by doubling its size. However, there were two(!) issues here: * If this was the first resize, the buffer size was set to 1024. This may not be enough (i.e. there may be more than 1024 bytes to process). * In all other cases, the buffer size was doubled. However, there is still no guarantee the buffer is large enough. Fix by looping until the buffer *is* large enough.
This commit is contained in:
parent
aeeef4f236
commit
f2d25c8341
2 changed files with 2 additions and 1 deletions
|
@ -40,6 +40,7 @@
|
||||||
([#330][330]).
|
([#330][330]).
|
||||||
* i3/sway: incorrect empty/title state of workspaces ([#343][343]).
|
* i3/sway: incorrect empty/title state of workspaces ([#343][343]).
|
||||||
* mem: state updated on each bar redraw ([#352][352]).
|
* mem: state updated on each bar redraw ([#352][352]).
|
||||||
|
* script: buffer overflow when reading large amounts of data.
|
||||||
|
|
||||||
[311]: https://codeberg.org/dnkl/yambar/issues/311
|
[311]: https://codeberg.org/dnkl/yambar/issues/311
|
||||||
[302]: https://codeberg.org/dnkl/yambar/issues/302
|
[302]: https://codeberg.org/dnkl/yambar/issues/302
|
||||||
|
|
|
@ -298,7 +298,7 @@ data_received(struct module *mod, const char *data, size_t len)
|
||||||
{
|
{
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
||||||
if (len > m->recv_buf.sz - m->recv_buf.idx) {
|
while (len > m->recv_buf.sz - m->recv_buf.idx) {
|
||||||
size_t new_sz = m->recv_buf.sz == 0 ? 1024 : m->recv_buf.sz * 2;
|
size_t new_sz = m->recv_buf.sz == 0 ? 1024 : m->recv_buf.sz * 2;
|
||||||
char *new_buf = realloc(m->recv_buf.data, new_sz);
|
char *new_buf = realloc(m->recv_buf.data, new_sz);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue