diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-09-18 20:44:06 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-09-18 17:15:03 +0200 |
commit | d836d9e345865245bab28100a6065d6fa7b6a00c (patch) | |
tree | e75d287f4bfac9f580ab70273e4b0e12ce86e7a5 /util.h | |
parent | bfc294b90dc46d132a56dc0a2ae118f2bea5a266 (diff) | |
download | passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar.gz passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar.bz2 passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar.lz passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar.xz passt-d836d9e345865245bab28100a6065d6fa7b6a00c.tar.zst passt-d836d9e345865245bab28100a6065d6fa7b6a00c.zip |
util: Remove possible quadratic behaviour from write_remainder()
write_remainder() steps through the buffers in an IO vector writing out
everything past a certain byte offset. However, on each iteration it
rescans the buffer from the beginning to find out where we're up to. With
an unfortunate set of write sizes this could lead to quadratic behaviour.
In an even less likely set of circumstances (total vector length > maximum
size_t) the 'skip' variable could overflow. This is one factor in a
longstanding Coverity error we've seen (although I still can't figure out
the remainder of its complaint).
Rework write_remainder() to always work out our new position in the vector
relative to our old/current position, rather than starting from the
beginning each time. As a bonus this seems to fix the Coverity error.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.h')
0 files changed, 0 insertions, 0 deletions