]> git.ipfire.org Git - thirdparty/git.git/blobdiff - http-push.c
Remove "pathlen" from "struct name_entry"
[thirdparty/git.git] / http-push.c
index cec7bf7fad9ccabc55d4e72c8dfb6bbe0ad3a1be..cbb02d3bc1eef3d5a088be320a3a8bcb87a4a685 100644 (file)
@@ -479,7 +479,7 @@ static void start_put(struct transfer_request *request)
        char *hex = sha1_to_hex(request->obj->sha1);
        struct active_request_slot *slot;
        char *posn;
-       char type[20];
+       enum object_type type;
        char hdr[50];
        void *unpacked;
        unsigned long len;
@@ -487,8 +487,8 @@ static void start_put(struct transfer_request *request)
        ssize_t size;
        z_stream stream;
 
-       unpacked = read_sha1_file(request->obj->sha1, type, &len);
-       hdrlen = sprintf(hdr, "%s %lu", type, len) + 1;
+       unpacked = read_sha1_file(request->obj->sha1, &type, &len);
+       hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
 
        /* Set it up */
        memset(&stream, 0, sizeof(stream));
@@ -1060,8 +1060,8 @@ static int fetch_indices(void)
                case 'P':
                        i++;
                        if (i + 52 < buffer.posn &&
-                           !strncmp(data + i, " pack-", 6) &&
-                           !strncmp(data + i + 46, ".pack\n", 6)) {
+                           !prefixcmp(data + i, " pack-") &&
+                           !prefixcmp(data + i + 46, ".pack\n")) {
                                get_sha1_hex(data + i + 6, sha1);
                                setup_index(sha1);
                                i += 51;
@@ -1206,11 +1206,11 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
                        lock->owner = xmalloc(strlen(ctx->cdata) + 1);
                        strcpy(lock->owner, ctx->cdata);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
-                       if (!strncmp(ctx->cdata, "Second-", 7))
+                       if (!prefixcmp(ctx->cdata, "Second-"))
                                lock->timeout =
                                        strtol(ctx->cdata + 7, NULL, 10);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
-                       if (!strncmp(ctx->cdata, "opaquelocktoken:", 16)) {
+                       if (!prefixcmp(ctx->cdata, "opaquelocktoken:")) {
                                lock->token = xmalloc(strlen(ctx->cdata) - 15);
                                strcpy(lock->token, ctx->cdata + 16);
                        }
@@ -1271,7 +1271,9 @@ xml_cdata(void *userData, const XML_Char *s, int len)
        struct xml_ctx *ctx = (struct xml_ctx *)userData;
        free(ctx->cdata);
        ctx->cdata = xmalloc(len + 1);
-       strlcpy(ctx->cdata, s, len + 1);
+       /* NB: 's' is not null-terminated, can not use strlcpy here */
+       memcpy(ctx->cdata, s, len);
+       ctx->cdata[len] = '\0';
 }
 
 static struct remote_lock *lock_remote(const char *path, long timeout)
@@ -1473,7 +1475,8 @@ static void process_ls_object(struct remote_ls_ctx *ls)
                return;
        path += 8;
        obj_hex = xmalloc(strlen(path));
-       strlcpy(obj_hex, path, 3);
+       /* NB: path is not null-terminated, can not use strlcpy here */
+       memcpy(obj_hex, path, 2);
        strcpy(obj_hex + 2, path + 3);
        one_remote_object(obj_hex);
        free(obj_hex);
@@ -2168,9 +2171,10 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
                return;
 
        /* If it's a symref, set the refname; otherwise try for a sha1 */
-       if (!strncmp((char *)buffer.buffer, "ref: ", 5)) {
+       if (!prefixcmp((char *)buffer.buffer, "ref: ")) {
                *symref = xmalloc(buffer.posn - 5);
-               strlcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 5);
+               memcpy(*symref, (char *)buffer.buffer + 5, buffer.posn - 6);
+               (*symref)[buffer.posn - 6] = '\0';
        } else {
                get_sha1_hex(buffer.buffer, sha1);
        }