IIUC the C function strcpy copies the character string x to the character string y .

void strcpy(char x[], char y[]) {
    int i = 0;
    while (x[i] != 0) {
        y[i] = x[i];
        i = i + 1;

IIUC the above simple string copy program has a serious flaw: it has no way of knowing that y has enough space to receive x. If a programmer were able to execute strcpy with a long string x, the programmer might be able to write bytes all over memory, possibly even modifying code stored in subsequent memory locations and the modified code might take over the machine.

The above is just a theory and I'd like to try it in practice for a demo because I study computer security. Is there a good practical example somewhere?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.