1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3:messages: check reg->refcount == 0 before accessing other elements

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
Ralph Boehme 2018-03-27 16:05:30 +02:00 committed by Stefan Metzmacher
parent 0b04258981
commit fdcc162208

View File

@ -192,15 +192,23 @@ static bool messaging_register_event_context(struct messaging_context *ctx,
for (i=0; i<num_event_contexts; i++) {
struct messaging_registered_ev *reg = &ctx->event_contexts[i];
if (reg->ev == ev) {
reg->refcount += 1;
return true;
}
if (reg->refcount == 0) {
if (reg->ev != NULL) {
abort();
}
free_reg = reg;
/*
* We continue here and may find another
* free_req, but the important thing is
* that we continue to search for an
* existing registration in the loop.
*/
continue;
}
if (reg->ev == ev) {
reg->refcount += 1;
return true;
}
}
@ -231,10 +239,11 @@ static bool messaging_deregister_event_context(struct messaging_context *ctx,
for (i=0; i<num_event_contexts; i++) {
struct messaging_registered_ev *reg = &ctx->event_contexts[i];
if (reg->refcount == 0) {
continue;
}
if (reg->ev == ev) {
if (reg->refcount == 0) {
return false;
}
reg->refcount -= 1;
if (reg->refcount == 0) {