File pacemaker-handle-PID-string-properly.patch of Package pacemaker.14737

commit a2a52b9f8fa1de488976ed29899cce708410ff5c
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Fri Sep 22 17:01:19 2017 -0500

    Low: crmd,libcrmcommon,libcluster,tools: handle PID as string properly
    
    potential sizing and formatting issues found by
    Jan Pokorný <jpokorny@redhat.com>

Index: pacemaker/crmd/main.c
===================================================================
--- pacemaker.orig/crmd/main.c
+++ pacemaker/crmd/main.c
@@ -163,6 +163,7 @@ crmd_init(void)
         exit_code = 1;
     }
 
-    crm_info("%u stopped: %s (%d)", getpid(), pcmk_strerror(exit_code), exit_code);
+    crm_info("%lu stopped: %s (%d)",
+             (unsigned long) getpid(), pcmk_strerror(exit_code), exit_code);
     return crmd_fast_exit(exit_code);
 }
Index: pacemaker/crmd/te_utils.c
===================================================================
--- pacemaker.orig/crmd/te_utils.c
+++ pacemaker/crmd/te_utils.c
@@ -206,7 +206,8 @@ static void
 tengine_stonith_notify(stonith_t * st, stonith_event_t * st_event)
 {
     if(te_client_id == NULL) {
-        te_client_id = crm_strdup_printf("%s.%d", crm_system_name, getpid());
+        te_client_id = crm_strdup_printf("%s.%lu", crm_system_name,
+                                         (unsigned long) getpid());
     }
 
     if (st_event == NULL) {
Index: pacemaker/include/crm/common/procfs.h
===================================================================
--- pacemaker.orig/include/crm/common/procfs.h
+++ pacemaker/include/crm/common/procfs.h
@@ -30,9 +30,16 @@
 
 #include <sys/types.h>
 #include <dirent.h>
+#include <unistd.h>     /* for getpid() */
 
 int crm_procfs_process_info(struct dirent *entry, char *name, int *pid);
 int crm_procfs_pid_of(const char *name);
 unsigned int crm_procfs_num_cores(void);
 
+static inline char *
+crm_getpid_s()
+{
+    return crm_strdup_printf("%lu", (unsigned long) getpid());
+}
+
 #endif /* CRM_COMMON_PROCFS__H */
Index: pacemaker/lib/cluster/cpg.c
===================================================================
--- pacemaker.orig/lib/cluster/cpg.c
+++ pacemaker/lib/cluster/cpg.c
@@ -315,7 +315,7 @@ pcmk_message_common_cs(cpg_handle_t hand
         goto badmsg;
 
     } else if (safe_str_eq("identify", data)) {
-        char *pid_s = crm_itoa((int) getpid());
+        char *pid_s = crm_getpid_s();
 
         send_cluster_text(crm_class_cluster, pid_s, TRUE, NULL, crm_msg_ais);
         free(pid_s);
Index: pacemaker/lib/common/logging.c
===================================================================
--- pacemaker.orig/lib/common/logging.c
+++ pacemaker/lib/common/logging.c
@@ -197,10 +197,11 @@ set_format_string(int method, const char
 
         if (uname(&res) == 0) {
             offset +=
-                snprintf(fmt + offset, FMT_MAX - offset, "%%t [%d] %s %10s: ", getpid(),
-                         res.nodename, daemon);
+                snprintf(fmt + offset, FMT_MAX - offset, "%%t [%lu] %s %10s: ",
+                         (unsigned long) getpid(), res.nodename, daemon);
         } else {
-            offset += snprintf(fmt + offset, FMT_MAX - offset, "%%t [%d] %10s: ", getpid(), daemon);
+            offset += snprintf(fmt + offset, FMT_MAX - offset, "%%t [%lu] %10s: ",
+                               (unsigned long) getpid(), daemon);
         }
     }
 
@@ -362,7 +363,8 @@ crm_control_blackbox(int nsig, bool enab
         pid_t pid = getpid();
 
         blackbox_file_prefix = malloc(NAME_MAX);
-        snprintf(blackbox_file_prefix, NAME_MAX, "%s/%s-%d", CRM_BLACKBOX_DIR, crm_system_name, pid);
+        snprintf(blackbox_file_prefix, NAME_MAX, "%s/%s-%lu",
+                 CRM_BLACKBOX_DIR, crm_system_name, (unsigned long) pid);
     }
 
     if (enable && qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_STATE_GET, 0) != QB_LOG_STATE_ENABLED) {
@@ -850,7 +852,7 @@ crm_log_init(const char *entity, uint8_t
             {
                 char path[512];
 
-                snprintf(path, 512, "%s-%d", crm_system_name, getpid());
+                snprintf(path, 512, "%s-%lu", crm_system_name, (unsigned long) getpid());
                 mkdir(path, 0750);
                 chdir(path);
                 crm_info("Changed active directory to %s/%s/%s", base, pwent->pw_name, path);
Index: pacemaker/tools/crm_node.c
===================================================================
--- pacemaker.orig/tools/crm_node.c
+++ pacemaker/tools/crm_node.c
@@ -154,9 +154,7 @@ int tools_remove_node_cache(const char *
     }
 
     if(safe_str_eq(target, CRM_SYSTEM_CRMD)) {
-        admin_uuid = calloc(1, 11);
-        snprintf(admin_uuid, 10, "%d", getpid());
-        admin_uuid[10] = '\0';
+        admin_uuid = crm_getpid_s();
 
         hello = create_hello_message(admin_uuid, "crm_node", "0", "1");
         rc = crm_ipc_send(conn, hello, 0, 0, NULL);
Index: pacemaker/tools/crm_resource.c
===================================================================
--- pacemaker.orig/tools/crm_resource.c
+++ pacemaker/tools/crm_resource.c
@@ -562,11 +562,7 @@ main(int argc, char **argv)
         return crm_exit(EX_USAGE);
     }
 
-    our_pid = calloc(1, 11);
-    if (our_pid != NULL) {
-        snprintf(our_pid, 10, "%d", getpid());
-        our_pid[10] = '\0';
-    }
+    our_pid = crm_getpid_s();
 
     if (do_force) {
         crm_debug("Forcing...");
Index: pacemaker/tools/crm_resource_runtime.c
===================================================================
--- pacemaker.orig/tools/crm_resource_runtime.c
+++ pacemaker/tools/crm_resource_runtime.c
@@ -562,11 +562,7 @@ send_lrm_rsc_op(crm_ipc_t * crmd_channel
     crm_xml_add(params, key, "60000");  /* 1 minute */
     free(key);
 
-    our_pid = calloc(1, 11);
-    if (our_pid != NULL) {
-        snprintf(our_pid, 10, "%d", getpid());
-        our_pid[10] = '\0';
-    }
+    our_pid = crm_getpid_s();
     cmd = create_request(op, msg_data, router_node, CRM_SYSTEM_CRMD, crm_system_name, our_pid);
 
 /* 	crm_log_xml_warn(cmd, "send_lrm_rsc_op"); */
@@ -961,7 +957,7 @@ update_dataset(cib_t *cib, pe_working_se
     }
 
     if(simulate) {
-        pid = crm_itoa(getpid());
+        pid = crm_getpid_s();
         shadow_cib = cib_shadow_new(pid);
         shadow_file = get_shadow_file(pid);
 
Index: pacemaker/tools/crm_simulate.c
===================================================================
--- pacemaker.orig/tools/crm_simulate.c
+++ pacemaker/tools/crm_simulate.c
@@ -432,7 +432,7 @@ setup_input(const char *input, const cha
     }
 
     if (output == NULL) {
-        char *pid = crm_itoa(getpid());
+        char *pid = crm_getpid_s();
 
         local_output = get_shadow_file(pid);
         temp_shadow = strdup(local_output);
Index: pacemaker/tools/crmadmin.c
===================================================================
--- pacemaker.orig/tools/crmadmin.c
+++ pacemaker/tools/crmadmin.c
@@ -408,11 +408,7 @@ do_init(void)
     mainloop_io_t *source =
         mainloop_add_ipc_client(CRM_SYSTEM_CRMD, G_PRIORITY_DEFAULT, 0, NULL, &crm_callbacks);
 
-    admin_uuid = calloc(1, 11);
-    if (admin_uuid != NULL) {
-        snprintf(admin_uuid, 10, "%d", getpid());
-        admin_uuid[10] = '\0';
-    }
+    admin_uuid = crm_getpid_s();
 
     crmd_channel = mainloop_get_ipc_client(source);
 
openSUSE Build Service is sponsored by