Skip to content

Commit

Permalink
Make buf_append_utf16le() suitable for validation-only
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 31, 2014
1 parent 5cfe6f8 commit 0f911e4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions http.c
Expand Up @@ -206,22 +206,28 @@ int buf_append_utf16le(struct oc_text_buf *buf, const char *utf8)
min = 0x10000;
} else {
if (buf)
buf->error = -EINVAL;
return -EINVAL;
buf->error = -EILSEQ;
return -EILSEQ;
}

while (nr_extra--) {
c = *(utf8++);
if ((c & 0xc0) != 0x80) {
if (buf)
buf->error = -EINVAL;
return -EINVAL;
buf->error = -EILSEQ;
return -EILSEQ;
}
utfchar <<= 6;
utfchar |= (c & 0x3f);
}
if (utfchar > 0x10ffff || utfchar < min)
return -EINVAL;
if (utfchar > 0x10ffff || utfchar < min) {
if (buf)
buf->error = -EILSEQ;
return -EILSEQ;
}

if (!buf)
continue;

if (utfchar >= 0x10000) {
utfchar -= 0x10000;
Expand All @@ -241,6 +247,10 @@ int buf_append_utf16le(struct oc_text_buf *buf, const char *utf8)
}
}

/* We were only being used for validation */
if (!buf)
return 0;

/* Ensure UTF16 is NUL-terminated */
if (buf_ensure_space(buf, 2))
return buf_error(buf);
Expand Down

0 comments on commit 0f911e4

Please sign in to comment.