]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Fix first line length in buf_append_base64()
authorDavid Woodhouse <dwmw2@infradead.org>
Wed, 19 May 2021 08:32:41 +0000 (09:32 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Wed, 19 May 2021 08:32:41 +0000 (09:32 +0100)
We need to add four (for the characters we're about to append) *after*
checking against line_len and resetting ll to zero. Otherwise the first
line thinks it starts at 4 while the others start at 0.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
textbuf.c

index dc9a32e51d0f508780fca1aa5958fcc8eda36fb4..a8b22a48dbbbeeb3b623112dc27b54ce13f959f8 100644 (file)
--- a/textbuf.c
+++ b/textbuf.c
@@ -438,11 +438,11 @@ void buf_append_base64(struct oc_text_buf *buf, const void *bytes, int len,
        int ll = 0;
        while (len > 0) {
                if (line_len) {
-                       ll += 4;
                        if (ll >= line_len) {
                                ll = 0;
                                buf->data[buf->pos++] = '\n';
                        }
+                       ll += 4;
                }
 
                buf->data[buf->pos++] = b64_table[in[0] >> 2];