net/mqtt: fix race condition in mqtt_init()
We need to set the mqtt context recv function prior to calling net_context_recv which installs the mqtt_recv callback. If not, we risk a race condition where an unprotected reference to mqtt->rcv(mqtt, buf) is made in mqtt_recv(). Change-Id: If90ee58f4ea6f7879ef7c12b969ba27647426acc Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
This commit is contained in:
parent
ff3b019054
commit
5fab97c9d0
1 changed files with 5 additions and 5 deletions
|
@ -837,11 +837,6 @@ int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type)
|
|||
ctx->clean_session = 1;
|
||||
ctx->connected = 0;
|
||||
|
||||
/* Install the receiver callback, timeout is set to K_NO_WAIT.
|
||||
* In this case, no return code is evaluated.
|
||||
*/
|
||||
(void)net_context_recv(ctx->net_ctx, mqtt_recv, K_NO_WAIT, ctx);
|
||||
|
||||
ctx->app_type = app_type;
|
||||
|
||||
switch (ctx->app_type) {
|
||||
|
@ -855,5 +850,10 @@ int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Install the receiver callback, timeout is set to K_NO_WAIT.
|
||||
* In this case, no return code is evaluated.
|
||||
*/
|
||||
(void)net_context_recv(ctx->net_ctx, mqtt_recv, K_NO_WAIT, ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue