~kennylevinsen/gtkgreet

3471aaaaee4619fd4aded85803b27b4a8dff41a6 — Ryan Farley 24 days ago d8f9c85 master
proto: use uint32_t offsets and message lengths

As the protocol imposes a hard 32-bit limit on message size, and the
affected functions' offset value can never go negative, just use
uint32_t for the lot. Fully fixes the signedness errors partially
corrected in b8218e3fae78fc9977fa867a121ae11b2ab35d4e while avoiding
the possibility of silent truncation (either through an overlong
message or running on a big-endian host).
1 files changed, 8 insertions(+), 4 deletions(-)

M gtkgreet/proto.c
M gtkgreet/proto.c => gtkgreet/proto.c +8 -4
@@ 21,9 21,13 @@ struct header {

static int write_req(int fd, struct json_object* req) {
    const char* reqstr = json_object_get_string(req);
    ssize_t len = (ssize_t)strlen(reqstr);
    char* headerp = (char*)&len;
    ssize_t off = 0;
    size_t len = strlen(reqstr);
    if (len > 0xFFFFFFFF) {
	    goto error;
    }
    uint32_t header = len;
    char* headerp = (char*)&header;
    uint32_t off = 0;

    while (off < 4) {
        ssize_t n = write(fd, &headerp[off], 4-off);


@@ 51,7 55,7 @@ static struct json_object* read_resp(int fd) {
    struct json_object* resp = NULL;
    char *respstr = NULL;
    uint32_t len;
    ssize_t off = 0;
    uint32_t off = 0;

    while (off < 4) {
        char* headerp = (char*)&len;