summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Gauthier <laurent.gauthier@soccasys.com>2023-05-24 06:44:53 +0000
committerJan Rybar <jrybar@redhat.com>2023-05-24 06:44:53 +0000
commit5615ed043fa8d9756ea79c60f09110f29efaa081 (patch)
tree6f3b2badd74a9fabee0e15903fce12e34f1964dc
parent4c6d183b0565185f4f7f9bea9f234326d7ea17d7 (diff)
duktape: prevent wrongful termination of runaway thread
-rw-r--r--src/polkitbackend/polkitbackendduktapeauthority.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/polkitbackend/polkitbackendduktapeauthority.c b/src/polkitbackend/polkitbackendduktapeauthority.c
index 02dbcfe..dc13971 100644
--- a/src/polkitbackend/polkitbackendduktapeauthority.c
+++ b/src/polkitbackend/polkitbackendduktapeauthority.c
@@ -556,12 +556,25 @@ runaway_killer_thread_execute_js (gpointer user_data)
}
g_free(contents);
+ if ((pthread_err = pthread_mutex_lock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error locking mutex: %s",
+ strerror(pthread_err));
+ return NULL;
+ }
+
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_SUCCESS;
goto end;
free_err:
g_free(contents);
err:
+ if ((pthread_err = pthread_mutex_lock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error locking mutex: %s",
+ strerror(pthread_err));
+ return NULL;
+ }
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
end:
if ((pthread_err = pthread_cond_signal(&ctx->cond))) {
@@ -570,6 +583,12 @@ end:
strerror(pthread_err));
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
}
+ if ((pthread_err = pthread_mutex_unlock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error unlocking mutex: %s",
+ strerror(pthread_err));
+ ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
+ }
return NULL;
}
@@ -595,10 +614,23 @@ runaway_killer_thread_call_js (gpointer user_data)
goto err;
}
+ if ((pthread_err = pthread_mutex_lock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error locking mutex: %s",
+ strerror(pthread_err));
+ return NULL;
+ }
+
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_SUCCESS;
goto end;
err:
+ if ((pthread_err = pthread_mutex_lock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error locking mutex: %s",
+ strerror(pthread_err));
+ return NULL;
+ }
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
end:
if ((pthread_err = pthread_cond_signal(&ctx->cond))) {
@@ -607,6 +639,13 @@ end:
strerror(pthread_err));
ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
}
+ if ((pthread_err = pthread_mutex_unlock(&ctx->mutex))) {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (ctx->authority),
+ "Error unlocking mutex: %s",
+ strerror(pthread_err));
+ ctx->ret = RUNAWAY_KILLER_THREAD_EXIT_STATUS_FAILURE;
+ }
+
return NULL;
}