Compare commits
2 commits
2fb13032ab
...
98c7d8b648
Author | SHA1 | Date | |
---|---|---|---|
|
98c7d8b648 | ||
|
7cdd84ac63 |
3 changed files with 10 additions and 19 deletions
6
match.c
6
match.c
|
@ -178,7 +178,7 @@ fail:
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
int match_check_sender(Bus *s, BusClient *sender_client, MatchRule *rule)
|
||||
int match_check_sender(BusClient *sender_client, MatchRule *rule)
|
||||
{
|
||||
if (rule->sender) {
|
||||
if (sender_client->unique_name) {
|
||||
|
@ -196,7 +196,7 @@ int match_check_sender(Bus *s, BusClient *sender_client, MatchRule *rule)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int match_rule_check(Bus *s, BusClient *sender_client, MatchRule *rule, WireMsg *msg, WireCtx *ctx)
|
||||
int match_rule_check(BusClient *sender_client, MatchRule *rule, WireMsg *msg, WireCtx *ctx)
|
||||
{
|
||||
if (rule->type && msg->type != rule->type) {
|
||||
return -1;
|
||||
|
@ -208,7 +208,7 @@ int match_rule_check(Bus *s, BusClient *sender_client, MatchRule *rule, WireMsg
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (match_check_sender(s, sender_client, rule) < 0) {
|
||||
if (match_check_sender(sender_client, rule) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
2
match.h
2
match.h
|
@ -8,6 +8,6 @@
|
|||
|
||||
void match_rule_free(MatchRule *rule);
|
||||
MatchRule *match_rule_from_string(char *d);
|
||||
int match_rule_check(Bus *s, BusClient *sender_client, MatchRule *rule, WireMsg *msg, WireCtx *ctx);
|
||||
int match_rule_check(BusClient *sender_client, MatchRule *rule, WireMsg *msg, WireCtx *ctx);
|
||||
|
||||
#endif // _JITTERBUG__MATCH_H
|
||||
|
|
21
server.c
21
server.c
|
@ -196,7 +196,7 @@ BusName *bus_name_add(Bus *s, char *name, BusClient *client)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int bus_client_match_add(Bus *s, BusClient *c, char *match)
|
||||
int bus_client_match_add(BusClient *c, char *match)
|
||||
{
|
||||
for (int i = 0; i < BUS_MAX_MATCH; i++) {
|
||||
if (!c->matches[i]) {
|
||||
|
@ -325,7 +325,7 @@ int bus_broadcast_message(Bus *s, BusClient *sender_client, WireMsg *msg, WireCt
|
|||
match_left--;
|
||||
|
||||
uint32_t previous_cursor = ctx->byte_cursor;
|
||||
if (match_rule_check(s, sender_client, c->matches[j], msg, ctx) >= 0) {
|
||||
if (match_rule_check(sender_client, c->matches[j], msg, ctx) >= 0) {
|
||||
TRYST(wire_compose_unicast_reply(reply_ctx, ctx, msg, sender_client->unique_name->name));
|
||||
TRYST(send(c->fd, reply_ctx->data, reply_ctx->byte_cursor, 0));
|
||||
// TODO?
|
||||
|
@ -360,7 +360,7 @@ int bus_broadcast_signal(Bus *s, BusClient *client, WireCtx *ctx, WireMsg *msg)
|
|||
}
|
||||
|
||||
match_left--;
|
||||
if (match_rule_check(s, client, c->matches[j], msg, ctx) >= 0) {
|
||||
if (match_rule_check(client, c->matches[j], msg, ctx) >= 0) {
|
||||
uint32_t previous_cursor = ctx->byte_cursor;
|
||||
TRYST(send(c->fd, ctx->data, ctx->byte_cursor, 0));
|
||||
ctx->byte_cursor = previous_cursor;
|
||||
|
@ -399,6 +399,7 @@ int bus_unicast_message(Bus *s, WireMsg *msg, WireCtx *ctx, char *target_name, c
|
|||
|
||||
|
||||
#define _reply_begin(M_sig) \
|
||||
(void)s; \
|
||||
uint32_t *body_length = NULL; \
|
||||
uint32_t body_start = 0; \
|
||||
if (!(msg->flags & DBUS_FLAG_NO_REPLY_EXPECTED)) { \
|
||||
|
@ -569,7 +570,7 @@ int handle_add_match(Bus *s, BusClient *client, WireMsg *msg, WireCtx *ctx, Wire
|
|||
|
||||
VERBOSE("client index %d adding match rule: '%s'\n", client->fd_index, match);
|
||||
|
||||
TRYST(bus_client_match_add(s, client, match));
|
||||
TRYST(bus_client_match_add(client, match));
|
||||
|
||||
_reply_begin("") {} _reply_end()
|
||||
return 0;
|
||||
|
@ -814,16 +815,6 @@ int bus_turn(Bus *s)
|
|||
static const char auth_data[] = "DATA\r\n";
|
||||
static const int data_buffer_len = 16384;
|
||||
|
||||
// We can keep a padding of null bytes for the data buffer. In the event that, for
|
||||
// example, a string function is called on a char array without a proper ending null
|
||||
// byte, we will reach the null bytes here at the end instead, thus preventing a
|
||||
// crash and potential corruption. While this is a good "last line of defense"
|
||||
// against such issues, it is much more important for these kinds of bugs to not
|
||||
// exist in the first place. This mitigation will prevent, for example, ASAN from
|
||||
// finding such bugs. It's recommended that you disable this padding outside
|
||||
// of production so that you can find these bugs.
|
||||
static const int data_buffer_padding = 0;
|
||||
|
||||
TRYST(poll(s->fds, s->fd_num, -1));
|
||||
|
||||
for (int i = 0; i < s->fd_num; i++) {
|
||||
|
@ -864,7 +855,7 @@ int bus_turn(Bus *s)
|
|||
}
|
||||
|
||||
// We add padding. See above.
|
||||
char data[data_buffer_len + data_buffer_padding];
|
||||
char data[data_buffer_len];
|
||||
ssize_t bytes = recv(fd, data, data_buffer_len, 0);
|
||||
if (bytes <= 0) {
|
||||
// error during recv() OR client disconnected, disconnect the client
|
||||
|
|
Loading…
Reference in a new issue