]> gitweb.ps.run Git - ps-cgit/blobdiff - parsing.c
syntax-highlighting.sh: Fix command injection.
[ps-cgit] / parsing.c
index c9e43509242d1d3a4e6faf85da7ce46375659ab3..1b2a551417f621733eaa4c5bbe2d5e8bf3de75dc 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -56,6 +56,8 @@ char *substr(const char *head, const char *tail)
 {
        char *buf;
 
 {
        char *buf;
 
+       if (tail < head)
+               return xstrdup("");
        buf = xmalloc(tail - head + 1);
        strncpy(buf, head, tail - head);
        buf[tail - head] = '\0';
        buf = xmalloc(tail - head + 1);
        strncpy(buf, head, tail - head);
        buf[tail - head] = '\0';
@@ -103,7 +105,10 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
 {
        char *tmp;
 
 {
        char *tmp;
 
-       if (!txt || !*txt || !src_enc || !dst_enc)
+       if (!txt)
+               return NULL;
+
+       if (!*txt || !src_enc || !dst_enc)
                return *txt;
 
        /* no encoding needed if src_enc equals dst_enc */
                return *txt;
 
        /* no encoding needed if src_enc equals dst_enc */
@@ -122,7 +127,7 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
 struct commitinfo *cgit_parse_commit(struct commit *commit)
 {
        struct commitinfo *ret;
 struct commitinfo *cgit_parse_commit(struct commit *commit)
 {
        struct commitinfo *ret;
-       char *p = commit->buffer, *t = commit->buffer;
+       char *p = commit->buffer, *t;
 
        ret = xmalloc(sizeof(*ret));
        ret->commit = commit;
 
        ret = xmalloc(sizeof(*ret));
        ret->commit = commit;