News for hackers. Stuff that matters.
Re:How security flaws work: the buffer overflow by georgerobinson on Wednesday August 26, 2015 @09:28AM (#10122690)
It's not just their size, but wouldn't all arrays need know the address of their first element too? For example, consider a simple char buffer:

    char buf[512];
where we want to read x number of bytes from a file descriptor starting from a offset other than the first element:

    read(fd, buf + 256, sizeof(buf)); // Whoops, incorrect sizeof, buffer overflow!
Could the compiler still detect this buffer overflow error without knowing the address of the first element in the array?

What about:

    char *dst = buf + 256;
    ...
    read(fd, dst, sizeof(buf));
perhaps the compiler could trace back all the calculations performed on the dst pointer to see whether this operation is valid?
Re:How security flaws work: the buffer overflow by jerf on Wednesday August 26, 2015 @12:42PM (#10124202)
The solution does involve storing a length, and this is called a Pascal string: https://en.wikipedia.org/wiki/String_%28computer_science%29#...

Many, many, many moons ago, C strings won out over Pascal strings. If the competition was somehow re-run from scratch today, with modern machines, it would be no contest: Pascal strings would win. But there was a time when every byte was precious. And not just "a bit precious", but very precious.

Re:How security flaws work: the buffer overflow by georgerobinson on Wednesday August 26, 2015 @03:12PM (#10125330)
Wow, that's incredible, thanks for the link!
Re:How security flaws work: the buffer overflow by TazeTSchnitzel on Wednesday August 26, 2015 @03:32PM (#10125449)
For this case, you can use "fat pointers" that include the size of their destination.