Code

Document git reflog --stale-fix
[git.git] / http-push.c
index 9ad6fd00b0bd96580bcebc5aa9ea1713e2b801cd..7c3720f602bb8f50ed54a4f7e7a85c7e08d1c07b 100644 (file)
@@ -9,6 +9,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "exec_cmd.h"
+#include "remote.h"
 
 #include <expat.h>
 
@@ -312,7 +313,7 @@ static void start_fetch_loose(struct transfer_request *request)
                SHA1_Init(&request->c);
                if (prev_posn>0) {
                        prev_posn = 0;
-                       lseek(request->local_fileno, SEEK_SET, 0);
+                       lseek(request->local_fileno, 0, SEEK_SET);
                        ftruncate(request->local_fileno, 0);
                }
        }
@@ -479,7 +480,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 +488,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));
@@ -517,7 +518,7 @@ static void start_put(struct transfer_request *request)
        request->buffer.size = stream.total_out;
        request->buffer.posn = 0;
 
-       request->url = xmalloc(strlen(remote->url) + 
+       request->url = xmalloc(strlen(remote->url) +
                               strlen(request->lock->token) + 51);
        strcpy(request->url, remote->url);
        posn = request->url + strlen(remote->url);
@@ -1271,7 +1272,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)
@@ -1295,7 +1298,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        sprintf(url, "%s%s", remote->url, path);
 
        /* Make sure leading directories exist for the remote ref */
-       ep = strchr(url + strlen(remote->url) + 11, '/');
+       ep = strchr(url + strlen(remote->url) + 1, '/');
        while (ep) {
                *ep = 0;
                slot = get_active_slot();
@@ -1473,7 +1476,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);
@@ -1747,8 +1751,7 @@ static struct object_list **process_tree(struct tree *tree,
        me.elem = name;
        me.elem_len = strlen(name);
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (S_ISDIR(entry.mode))
@@ -2170,7 +2173,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
        /* If it's a symref, set the refname; otherwise try for a sha1 */
        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);
        }