From: Timo Sirainen Date: Fri, 21 Jan 2022 09:27:47 +0000 (+0100) Subject: global: Write pid_t as unsigned number where it might end up used with kill() X-Git-Tag: 2.4.0~4472 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ccd0af8b5610f5ad5968283e3fb9ef1c3509fd7;p=thirdparty%2Fdovecot%2Fcore.git global: Write pid_t as unsigned number where it might end up used with kill() pid_t is signed, so usually it's been written to strings as signed long. The actual pid values should never be negative, so practically it shouldn't matter if it's written as signed or unsigned. However, due to bugs it's theoretically possible that some garbage value gets written out. kill() handles negative PIDs by killing entire process groups. By writing pid_t as unsigned number we can prevent any (theoretical) issues where kill() ends up killing entire process groups. Change only some of the places to unsigned where the value might end up used for kill(). Usually the signed writing is used only for log messages where it might be more useful to see the negative numbers clearly (especially -1 as unknown/unset might be used somewhere). --- diff --git a/src/anvil/connect-limit.c b/src/anvil/connect-limit.c index 03a103c11f..32be296fd1 100644 --- a/src/anvil/connect-limit.c +++ b/src/anvil/connect-limit.c @@ -563,7 +563,7 @@ void connect_limit_dump(struct connect_limit *limit, struct ostream *output) hash_table_iterate(iter, limit->session_hash, &conn_guid, &session)) T_BEGIN { str_truncate(str, 0); - str_printfa(str, "%ld\t", (long)session->process->pid); + str_printfa(str, "%lu\t", (unsigned long)session->process->pid); str_append_tabescaped(str, session->userip->username); str_append_c(str, '\t'); str_append_tabescaped(str, session->service); diff --git a/src/doveadm/doveadm-who.c b/src/doveadm/doveadm-who.c index 83f7c21d01..4f58c0c878 100644 --- a/src/doveadm/doveadm-who.c +++ b/src/doveadm/doveadm-who.c @@ -343,7 +343,7 @@ static void who_print_user(const struct who_user *user) str_append_c(str, '('); array_foreach_elem(&user->pids, pid) - str_printfa(str, "%ld ", (long)pid); + str_printfa(str, "%lu ", (unsigned long)pid); if (str_len(str) > 1) str_truncate(str, str_len(str)-1); str_append_c(str, ')'); diff --git a/src/master/master-client.c b/src/master/master-client.c index 82389ec18e..5384dc82d3 100644 --- a/src/master/master-client.c +++ b/src/master/master-client.c @@ -54,8 +54,8 @@ master_client_process_output(string_t *str, const struct service_process *process) { str_append_tabescaped(str, process->service->set->name); - str_printfa(str, "\t%ld\t%u\t%u\t%ld\t%ld\t%ld\n", - (long)process->pid, process->available_count, + str_printfa(str, "\t%lu\t%u\t%u\t%ld\t%ld\t%ld\n", + (unsigned long)process->pid, process->available_count, process->total_count, (long)process->idle_start, (long)process->last_status_update, (long)process->last_kill_sent); diff --git a/src/old-stats/client-export.c b/src/old-stats/client-export.c index e020d134fa..34ace73ed4 100644 --- a/src/old-stats/client-export.c +++ b/src/old-stats/client-export.c @@ -333,7 +333,7 @@ static int client_export_iter_session(struct client *client) } T_END; str_append_c(cmd->str, '\t'); str_append_tabescaped(cmd->str, session->service); - str_printfa(cmd->str, "\t%ld", (long)session->pid); + str_printfa(cmd->str, "\t%lu", (unsigned long)session->pid); str_printfa(cmd->str, "\t%d", !session->disconnected); client_export_timeval(cmd->str, &session->last_update); str_printfa(cmd->str, "\t%u\t", session->num_cmds);