News for hackers. Stuff that matters.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by revelation on Wednesday July 26, 2017 @06:53PM (#14861129)
C's lack of arrays strikes again. They are essentially syntactic sugar.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by frlnBorg on Wednesday July 26, 2017 @07:15PM (#14861235)
What do you mean by C not having arrays?
Re:Remotely Compromising Android and iOS via a bug in Broadc... by kinkrtyavimoodh on Wednesday July 26, 2017 @07:20PM (#14861262)
It's syntactic sugar in the sense that arr[i] is just shorthand for *(arr+i)

There's no abstraction or 'concept' of arrays there. You are literally just telling the compiler to take a certain pointer and move i steps ahead.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by corndoge on Wednesday July 26, 2017 @07:27PM (#14861315)
Isn't that the definition of an array? Chunk of contiguous memory plus a notion of how to subdivide it into equal parts?
Re:Remotely Compromising Android and iOS via a bug in Broadc... by kuschku on Wednesday July 26, 2017 @07:29PM (#14861327)
Yes, exactly. A chunk of memory. A chunk has an end.

But "arrays" in C aren't a chunk of memory, just the info where it starts and how large elements are.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by hedora on Wednesday July 26, 2017 @11:47PM (#14862551)
The problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this, and stdlib doesn't provide them either:

struct buf { uint8_t * base, size_t size };

Re:Remotely Compromising Android and iOS via a bug in Broadc... by kbenson on Thursday July 27, 2017 @12:07AM (#14862626)
> The problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this

That's likely because having to pass it in and out of functions and libs that don't expect your special structure might cause it to have an invalid length, and then all your special wrappers can become a liability and not an advantage through either assuming your bufs are valid, or defensively checking more than is necessarily because they can't know whether it was altered or not.

> stdlib doesn't provide them either

Which is the real problem. That would make them a de facto standard, and a lot (but probably not all) of the problems would be mitigated by people accepting the performance trade offs needed to make them safe.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by kbart on Thursday July 27, 2017 @02:01AM (#14862983)
That doesn't solve the problem because you still have to set 'size' manually.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by CobrastanJorji on Wednesday July 26, 2017 @07:19PM (#14861257)
I assume they mean that C's support for "arrays" is essentially just C's support for pointer arithmetic plus a mapping of a[b] to *(a+b).
Re:Remotely Compromising Android and iOS via a bug in Broadc... by Kubuxu on Wednesday July 26, 2017 @07:32PM (#14861354)
You can even swap it a[b] equivalent to b[a].
Re:Remotely Compromising Android and iOS via a bug in Broadc... by shitgoose on Wednesday July 26, 2017 @09:49PM (#14862014)
shouldn't it be:

* (a + b * sizeof(T))

where T is array elements' type?

Re:Remotely Compromising Android and iOS via a bug in Broadc... by astrange on Wednesday July 26, 2017 @11:02PM (#14862368)
That's implied in + on a pointer. uint32_t* + 1 actually adds 4.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by JustSomeNobody on Wednesday July 26, 2017 @07:18PM (#14861254)
Probably referring to the fact that they are simply pointers into contiguous memory.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by astrange on Wednesday July 26, 2017 @11:04PM (#14862377)
C doesn't have "memory" in the standard. They're pointers into a contiguous object, but anything before a[-1] or after a[sizeof(a)-1] is undefined aka it actually doesn't exist.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by DiThi on Sunday July 30, 2017 @08:17AM (#14885621)
`sizeof(a)` only gives the size of the array when the size is specified at compile time. Either you accept e.g. `int[16]` as a type, or you pass a pointer (for which `sizeof` just returns `sizeof(intptr_t)`)
Re:Remotely Compromising Android and iOS via a bug in Broadc... by nemetroid on Sunday July 30, 2017 @05:26PM (#14887915)
That's not quite right. Arrays always have a knowable length, and sizeof will give a correct result for variable length arrays as well.

However, arrays that are passed as arguments to functions decay into raw pointers, at which point you lose information about its length.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by DiThi on Monday July 31, 2017 @07:31AM (#14890975)
> sizeof will give a correct result for variable length arrays as well.

In C99 with rather spotty support. And never with malloc and similar, which is how the vast majority of arrays are (and can be) created. And you can't return or store those dynamic arrays somewhere else without losing the size info, nor it can be declared static.

In other words, you're right but for very limited situations.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by pmontra on Wednesday July 26, 2017 @07:22PM (#14861281)
They are a pointer and an offset with no validation of bounds. But that's OK: C is little more than a high level assembly.
Re:Remotely Compromising Android and iOS via a bug in Broadc... by armitron on Wednesday July 26, 2017 @08:21PM (#14861607)
I hate the term "high level assembly" when applied to C since it's loaded against assembly (in the sense of C as its superset) which is obviously not true.

C is full of undefined behavior, assembly is not.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by pmontra on Thursday July 27, 2017 @06:00AM (#14863893)
High level != Superset

Actually we often give up features and specialize with high level languages. That's why there are things easier to do in Ruby than in C++ and vice versa.

They are all (usually much more convenient) subsets of assembly.

Re:Remotely Compromising Android and iOS via a bug in Broadc... by antoinealb on Thursday July 27, 2017 @08:52AM (#14864773)
What ? Assembly has undefined behavior, for example wrt unaligned access on some processors.