// In revision.c before https://github.com/git/git/commit/34fa79a6cde56d6d428ab0d3160cb094ebad3305 char *path_name(const struct name_path *path, const char *name) // by design, name_path->len is a 32 bits int, but this doesn't concern name { const struct name_path *p; char *n, *m; int nlen = strlen(name); // the size is converted to a positive number (the correct size was allocated previously with an unsigned long). I got 705804100 int len = nlen + 1; for (p = path; p; p = p->up) { //loop is skipped (except for the cve-2016-2324 case which is fixed since 2.7.1 in February 2016) if (p->elem_len) len += p->elem_len + 1; } n = xmalloc(len); // if len is negative, it will also be converted to a negative 64 bits integer *(which explains it is normally trying to allocate serveral Pb of ram most of the time)* which will be read as positive after that. // but this isn't the run case that is interesting here. m = n + len - (nlen + 1); // the size of m is lower than name strcpy(m, name); // strcpy rely on the null terminating character. The result is written in an unallocated memory from heap. This is the definition of heap overflow enabling server side remote code execution if name[] contains assembly, and have the correct size. This open the way to defeat canaries aslr, and nx combined see http://security.stackexchange.com/q/20497/36301#comment182004_20550 for (p = path; p; p = p->up) { if (p->elem_len) { m -= p->elem_len + 1; memcpy(m, p->elem, p->elem_len); m[p->elem_len] = '/'; } } return n; }