Harvey-OS / harvey

A distributed operating system
https://harvey-os.org/
MIT License
1.44k stars 105 forks source link

devdraw should probably return Eshortread if you pass 144 characters #1163

Open floren opened 3 years ago

floren commented 3 years ago

Right now, in the drawread function, the Qctl case checks if the buffer is LESS than 144 characters:

                if(n < 12*12)
                        error(Eshortread);

But then it does this snprint:

                n = snprint(a, n,
                        "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ",
                        cl->clientid, cl->infoid, chantostr(buf, i->chan),
                        (i->flags&Frepl)==Frepl,
                        i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
                        i->clipr.min.x, i->clipr.min.y, i->clipr.max.x,
                        i->clipr.max.y);

That string is 144 characters long. snprint always leaves room for a NULL character at the end, so if you pass in a 144 character array (n = 144), it ends up chopping off the final space character. The return value is then 143.

This leads to a corner case where drawread isn't able to write the full string into memory, but it also doesn't return an error.