diff --git a/Makefile b/Makefile index 32dc177..7092888 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS_RELEASE=-O2 -fgraphite-identity -funroll-loops -ftree-vectorize -flto -gg CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99 -CFLAGS+=$(CFLAGS_RELEASE) +CFLAGS+=$(CFLAGS_DEV) jitterbug: util.c wire.c match.c server.c main.c $(CC) $(CFLAGS) -o $@ $^ diff --git a/server.c b/server.c index b8f05c0..2f586bc 100644 --- a/server.c +++ b/server.c @@ -225,9 +225,9 @@ BusName *bus_client_assign_unique_name(Bus *s, BusClient *client) if (client->unique_name) { return NULL; } - uint8_t id = 0; + uint16_t id = 0; - if (read(s->urandom_fd, &id, sizeof(uint8_t)) != sizeof(uint8_t)) { + if (read(s->urandom_fd, &id, sizeof(uint16_t)) != sizeof(uint16_t)) { return NULL; } @@ -236,7 +236,7 @@ BusName *bus_client_assign_unique_name(Bus *s, BusClient *client) return NULL; } - if (snprintf(name_str, UNIQUE_NAME_LENGTH, ":%05"PRIu16".%03"PRIu8, client->fd_index, id) != (UNIQUE_NAME_LENGTH - 1)) { + if (snprintf(name_str, UNIQUE_NAME_LENGTH, ":%05"PRIu16".000%05"PRIu16, client->fd_index + 1, id) != (UNIQUE_NAME_LENGTH - 1)) { free(name_str); return NULL; } @@ -297,7 +297,7 @@ void bus_client_remove(Bus *s, BusClient *c) c->owned_names[j] = NULL; } - bus_name_remove(s, c->unique_name); + // unique_name is included in owned_names, so we don't need to remove it again here c->unique_name = NULL; c->match_count = 0; c->fd = -1; diff --git a/wire.c b/wire.c index c728877..4912b4a 100644 --- a/wire.c +++ b/wire.c @@ -449,18 +449,22 @@ int wire_compose_unicast_reply(WireCtx *msg_c, WireMsg *msg, char *sender_unique TRYPTR(wire_set_u32(header_ctx, msg->serial)); /* serial */ uint32_t *header_fields_length = TRYPTR(wire_set_u32(header_ctx, 0)); /* header_fields_length */ - TRYPTR(wire_write_align(header_ctx, 8)); + // We don't need to do this because at this point we will always end up on an 8 byte alignment. + //TRYPTR(wire_write_align(header_ctx, 8)); uint32_t header_fields_start = header_ctx->byte_cursor; TRYPTR(wire_set_u8(header_ctx, DBUS_HEADER_FIELD_SENDER)); TRYPTR(wire_set_signature_single_char(header_ctx, 's')); TRYPTR(wire_set_string_fixed(header_ctx, sender_unique_name, UNIQUE_NAME_LENGTH)); - TRYPTR(wire_write_align(header_ctx, 8)); + + // We don't need to do this because the unique names are fixed-size, such that we always end up on an 8 byte alignment here. + //TRYPTR(wire_write_align(header_ctx, 8)); *header_fields_length = header_ctx->byte_cursor - header_fields_start + msg->header_fields_length; - if (msg_c->byte_cursor + msg->body_length >= msg_c->data_len) { + // TODO: is this right? + if (unlikely(msg_c->byte_cursor + msg->body_length >= msg_c->data_len)) { return -1; } diff --git a/wire.h b/wire.h index abd3d4c..2105d59 100644 --- a/wire.h +++ b/wire.h @@ -20,7 +20,7 @@ #define DBUS_FLAG_NO_AUTO_START 0x1 #define DBUS_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 0x1 -#define UNIQUE_NAME_LENGTH 11 +#define UNIQUE_NAME_LENGTH 16 enum { DBUS_HEADER_FIELD_INVALID = 0,