News for hackers. Stuff that matters.
Re:Nginx SPDY heap buffer overflow (affects 1.3.15 – 1.5.11) by unwind on Wednesday March 19, 2014 @04:08AM (#7427301)
Without context (I'm not familiar with nginx' code) the blatant subtraction of pointers was scary, too.

As everyone is of course no doubt aware, subtraction of pointers is only valid in C if you can guarantee that the pointers point to the same "object" (or at most 1 character past the end of an object).

I would prefer an interface using a size_t count of available space, rather than passing an end-pointer around.

Again, this is based solely on reading the patch, so it might be perfectly fine. Considering nginx' reputation, I guess it's academic.

Re:Nginx SPDY heap buffer overflow (affects 1.3.15 – 1.5.11) by ambrop7 on Wednesday March 19, 2014 @04:24AM (#7427335)
It's kind of implied by the parameters that they point to the same object; they're named "pos" and "end" after all. But I agree, a count variable is nicer.

The subtraction also has a (very theoretical) problem that its result must fit in ptrdiff_t (signed), and it would produce undefined behavior when you have a huge object whose size doesn't fit in ptrdiff_t (but does in size_t, by definition).

Re:Nginx SPDY heap buffer overflow (affects 1.3.15 – 1.5.11) by atom7 on Wednesday March 19, 2014 @04:20AM (#7427324)
It's a common practice to use two pointers when parsing some stream data buffer. If you will use a pointer to the start of the buffer and the size of an available data to parse, then you would need to change two variables instead of one on every parsing stage. So you have more opportunity to make a mistake.