diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Treat text blobs with stray nuls as binary
Diffstat (limited to '')
| -rw-r--r-- | source/ui-blob.c | 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 16 insertions, 3 deletions
diff --git a/source/ui-blob.c b/source/ui-blob.c index beb968b..db1d0c1 100644 --- a/source/ui-blob.c +++ b/source/ui-blob.c @@ -126,10 +126,23 @@ int cgit_print_file(char *path, const char *head, int file_only, int html_escape // html_txt wants a terminated string, and git leaves a spare byte // past every object it reads, so this write stays in the allocation. buf[size] = '\0'; - if (html_escape) - html_txt(buf); - else + if (html_escape) { + // html_txt stops at a NUL, so a blob holding one is written + // segment by segment with a replacement character standing in + // for each NUL byte, rather than silently cut short. + const char *p = buf, *end = buf + size; + + while (p < end) { + html_txt(p); + p += strlen(p); + while (p < end && !*p) { + html("\xef\xbf\xbd"); + p++; + } + } + } else { html_raw(buf, size); + } free(buf); return 0; } |
