Skip to content

Commit 04a176e

Browse files
michelesremersion
authored andcommitted
Fix race condition in get_logind_idle_inhibit()
See #38 (comment) Running sd_bus_message_unref() overrides the locks buffer under certain conditions. Comparing before running sd_bus_message_unref() will make sure that the inhibit lock will always be found correctly.
1 parent 85b57cc commit 04a176e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ static void set_idle_hint(bool hint) {
207207

208208
static bool get_logind_idle_inhibit(void) {
209209
const char *locks;
210+
bool res;
211+
210212
sd_bus_message *reply = NULL;
211213

212214
int ret = sd_bus_get_property(bus, DBUS_LOGIND_SERVICE, DBUS_LOGIND_PATH,
@@ -219,8 +221,11 @@ static bool get_logind_idle_inhibit(void) {
219221
if (ret < 0) {
220222
goto error;
221223
}
224+
225+
res = strstr(locks, "idle") != NULL;
222226
sd_bus_message_unref(reply);
223-
return strstr(locks, "idle") != NULL;
227+
228+
return res;
224229

225230
error:
226231
sd_bus_message_unref(reply);

0 commit comments

Comments
 (0)