From baa5ad1f80f56d3c0b0095bfb468fab28c9b4982 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 16 Jan 2016 11:03:05 +0000 Subject: ui-log: handle parse_commit() errors If parse_commit() fails, none of the fields in the commit structure will have been populated so we will dereference NULL when accessing item->tree. There isn't much we can do about the error at this point, but if we return true then we'll try parsing the commit again from print_commit() and we can report an error to the user at that point. Coverity-id: 13801 Signed-off-by: John Keeping --- ui-log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-log.c b/ui-log.c index 4573255..a4dc707 100644 --- a/ui-log.c +++ b/ui-log.c @@ -141,7 +141,9 @@ static int show_commit(struct commit *commit, struct rev_info *revs) /* When we get here we have precisely one parent. */ parent = parents->item; - parse_commit(parent); + /* If we can't parse the commit, let print_commit() report an error. */ + if (parse_commit(parent)) + return 1; files = 0; add_lines = 0; -- cgit v1.2.3 From 3fbfced7401cfcbb8006a9a6ce4add6b37a41a55 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 16 Jan 2016 11:03:06 +0000 Subject: cache: use size_t for string lengths Avoid integer truncation on 64-bit systems. Coverity-id: 13864 Signed-off-by: John Keeping --- cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.c b/cache.c index b169d20..df1b4a3 100644 --- a/cache.c +++ b/cache.c @@ -24,7 +24,7 @@ struct cache_slot { const char *key; - int keylen; + size_t keylen; int ttl; cache_fill_fn fn; int cache_fd; @@ -44,7 +44,7 @@ struct cache_slot { static int open_slot(struct cache_slot *slot) { char *bufz; - int bufkeylen = -1; + ssize_t bufkeylen = -1; slot->cache_fd = open(slot->cache_name, O_RDONLY); if (slot->cache_fd == -1) -- cgit v1.2.3 From 33bc949a1e927e14479568518bd92e70998e25f8 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 16 Jan 2016 11:03:07 +0000 Subject: cache: don't check for match with no key We call open_slot() from cache_ls() without a key since we simply want to read the path out of the header. Should the file happen to contain an empty key then we end up calling memcmp() with NULL and a non-zero length. Fix this by assigning slot->match only if a key is set, which is always will be in the code paths where we use slot->match. Coverity-id: 13807 Signed-off-by: John Keeping --- cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cache.c b/cache.c index df1b4a3..6736a01 100644 --- a/cache.c +++ b/cache.c @@ -61,8 +61,9 @@ static int open_slot(struct cache_slot *slot) if (bufz) bufkeylen = bufz - slot->buf; - slot->match = bufkeylen == slot->keylen && - !memcmp(slot->key, slot->buf, bufkeylen + 1); + if (slot->key) + slot->match = bufkeylen == slot->keylen && + !memcmp(slot->key, slot->buf, bufkeylen + 1); return 0; } -- cgit v1.2.3 From d3756bd7b00f9ad6adede3c7f956a25b22a2254a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 18 Jan 2016 11:14:06 +0100 Subject: syntax-highlighting: always use utf-8 to avoid ascii codec issues --- filters/syntax-highlighting.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index b5d615e..1ca4108 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -21,6 +21,7 @@ import sys +import io from pygments import highlight from pygments.util import ClassNotFound from pygments.lexers import TextLexer @@ -29,6 +30,8 @@ from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') data = sys.stdin.read() filename = sys.argv[1] formatter = HtmlFormatter(style='pastie') -- cgit v1.2.3 From 23f7dadaaba2817c92c42c0a642a3186aa8ef24d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 18 Jan 2016 15:56:45 +0100 Subject: ui-tree: put reverse path in title --- ui-tree.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ui-tree.c b/ui-tree.c index 3ff2320..120066c 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -84,6 +84,37 @@ static void print_binary_buffer(char *buf, unsigned long size) html("\n"); } +static void set_title_from_path(const char *path) +{ + size_t path_len, path_index, path_last_end; + char *new_title; + + if (!path) + return; + + path_len = strlen(path); + new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); + new_title[0] = '\0'; + + for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { + if (path[path_index] == '/') { + if (path_index == path_len - 1) { + path_last_end = path_index - 1; + continue; + } + strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); + strcat(new_title, "\\"); + path_last_end = path_index; + } + } + if (path_last_end) + strncat(new_title, path, path_last_end); + + strcat(new_title, " - "); + strcat(new_title, ctx.page.title); + ctx.page.title = new_title; +} + static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) { enum object_type type; @@ -104,6 +135,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base return; } + set_title_from_path(path); + cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, @@ -235,6 +268,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; + set_title_from_path(buffer); ls_head(); return READ_TREE_RECURSIVE; } else { -- cgit v1.2.3