I would expect to see compile errors from this code and perhaps an error when the executable is run. From my understanding, if a pointer is assigned and exists in the heap, and malloc reserves space for the pointer, if what is placed at the pointer is too large, it should start to override code space. However, this runs without issue on Linux 64 bit Ubuntu 14.04.
In this example, I am reserving 5 bytes initially but putting 21 bytes (\0 would be byte 21?) at that memory address. The program runs without issue and the compiler throws no error.
I compiled using the command: "gcc -Wextra -pedantic test.c -o test"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str;
/* Initial memory allocation */
str = malloc(5);
strcpy(str, "12345678901234567890");
printf("String = %s, Address = %p\n", str, str);
/* Reallocating memory */
str = realloc(str, 26);
strcat(str, "12345");
printf("String = %s, Address = %p\n", str, str);
free(str);
return(0);
}