]> git.proxmox.com Git - libgit2.git/commitdiff
pkt: don't use strlen before we know the name is NUL-terminated
authorCarlos Martín Nieto <carlos@cmartin.tk>
Wed, 7 Sep 2011 14:35:11 +0000 (16:35 +0200)
committerCarlos Martín Nieto <carlos@cmartin.tk>
Wed, 7 Sep 2011 14:37:19 +0000 (16:37 +0200)
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
src/pkt.c

index 4eac0411f89e0a6b42d18c6470e3b0b7be423055..f97246a09348dbe001df14b29cd6d1436e0e0cad 100644 (file)
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -104,7 +104,7 @@ static int pack_pkt(git_pkt **out)
 static int ref_pkt(git_pkt **out, const char *line, size_t len)
 {
        git_pkt_ref *pkt;
-       int error, has_caps = 0;
+       int error;
 
        pkt = git__malloc(sizeof(git_pkt_ref));
        if (pkt == NULL)
@@ -128,9 +128,6 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
        line += GIT_OID_HEXSZ + 1;
        len -= (GIT_OID_HEXSZ + 1);
 
-       if (strlen(line) < len)
-               has_caps = 1;
-
        if (line[len - 1] == '\n')
                --len;
 
@@ -142,7 +139,7 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
        memcpy(pkt->head.name, line, len);
        pkt->head.name[len] = '\0';
 
-       if (has_caps) {
+       if (strlen(pkt->head.name) < len) {
                pkt->capabilities = strchr(pkt->head.name, '\0') + 1;
        }