]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Write pid_t as unsigned number where it might end up used with kill()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 21 Jan 2022 09:27:47 +0000 (10:27 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 8 Feb 2022 09:48:24 +0000 (10:48 +0100)
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).

src/anvil/connect-limit.c
src/doveadm/doveadm-who.c
src/master/master-client.c
src/old-stats/client-export.c

index 03a103c11fc46516ca499d2ace47f68e95650df1..32be296fd1f72a08c9c18a1c82619c5bfa6e0db6 100644 (file)
@@ -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);
index 83f7c21d0101ebd91f71d92a61350df11c86815b..4f58c0c878096cc2ade702b4001838041daae06c 100644 (file)
@@ -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, ')');
index 82389ec18eb5cd60bfa42bffb86c4bb41e6b1b82..5384dc82d392887dcd207084e7526bfc7421bda7 100644 (file)
@@ -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);
index e020d134faf9401a64f1206c2f3cd11c99583a3a..34ace73ed47aece377797d35d657435baec8b485 100644 (file)
@@ -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);