]> git.proxmox.com Git - mirror_corosync-qdevice.git/commitdiff
msg: Check cat result on adding msg type and size
authorJan Friesse <jfriesse@redhat.com>
Wed, 4 Nov 2020 16:37:43 +0000 (17:37 +0100)
committerJan Friesse <jfriesse@redhat.com>
Wed, 4 Nov 2020 16:52:04 +0000 (17:52 +0100)
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
qdevices/msg.c

index e778f825d9b01ea2ceb598107cc0c35d46d367ce..954be621b7f4bff1a48eb18204104e71b735d2c9 100644 (file)
@@ -73,13 +73,16 @@ msg_get_header_length(void)
        return (MSG_TYPE_LENGTH + MSG_LENGTH_LENGTH);
 }
 
-static void
+static int
 msg_add_type(struct dynar *msg, enum msg_type type)
 {
        uint16_t ntype;
+       int res;
 
        ntype = htons((uint16_t)type);
-       dynar_cat(msg, &ntype, sizeof(ntype));
+       res = dynar_cat(msg, &ntype, sizeof(ntype));
+
+       return (res);
 }
 
 enum msg_type
@@ -98,13 +101,16 @@ msg_get_type(const struct dynar *msg)
  * We don't know size of message before call of this function, so zero is
  * added. Real value is set afterwards by msg_set_len.
  */
-static void
+static int
 msg_add_len(struct dynar *msg)
 {
        uint32_t len;
+       int res;
 
        len = 0;
-       dynar_cat(msg, &len, sizeof(len));
+       res = dynar_cat(msg, &len, sizeof(len));
+
+       return (res);
 }
 
 static void
@@ -148,8 +154,13 @@ msg_create_preinit(struct dynar *msg, const char *cluster_name, int add_msg_seq_
 
        dynar_clean(msg);
 
-       msg_add_type(msg, MSG_TYPE_PREINIT);
-       msg_add_len(msg);
+       if (msg_add_type(msg, MSG_TYPE_PREINIT) == -1) {
+               goto small_buf_err;
+       }
+
+       if (msg_add_len(msg) == -1) {
+               goto small_buf_err;
+       }
 
        if (add_msg_seq_number) {
                if (tlv_add_msg_seq_number(msg, msg_seq_number) == -1) {