]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix a couple of memory leaks in drag-and-drop/copy-paste code:
authorKruti Pendharkar <kp025370@broadcom.com>
Tue, 25 Feb 2025 09:29:11 +0000 (01:29 -0800)
committerKruti Pendharkar <kp025370@broadcom.com>
Tue, 25 Feb 2025 09:29:11 +0000 (01:29 -0800)
* `CopyPasteRpcV3::HandleMsg` calls `CPClipboard_Unserialize`
which allocates memory to the supplied `Clipboard`
structure, but it neglected to call `CPClipboard_Destroy`
to free it when done.  Also update the documentation for
`CPClipboard_Unserialize` to make the contract more
explicit.
* `DnD_SetCPClipboardFromLocalText` completely neglected to
free its destination buffer.

Bonus cleanup:

* Make some pointers `const` (which also allows us to remove
some casts).
* Replace a call to `UNICODE_RELEASE_UTF16` with `free` since
the memory was allocated by lib/dnd with `malloc` and was
not allocated by lib/unicode.

open-vm-tools/services/plugins/dndcp/dnd/dnd.h
open-vm-tools/services/plugins/dndcp/dnd/dndClipboard.c
open-vm-tools/services/plugins/dndcp/dnd/dndMsg.c
open-vm-tools/services/plugins/dndcp/dnd/dndMsg.h

index f6b95035137fdd2ec2d863d9e923ddc7bc843afa..913cf5c11d067c65bfc75526b5931f89d2daaf59 100644 (file)
@@ -231,10 +231,10 @@ HGLOBAL DnD_CreateHDropForGuest(const char *path,
                                 const char *fileList);
 size_t DnD_CPStringToLocalString(const char *bufIn,
                                  utf16_t **bufOut);
-size_t DnD_LocalStringToCPString(utf16_t *bufIn,
+size_t DnD_LocalStringToCPString(const utf16_t *bufIn,
                                  char **bufOut);
 Bool DnD_SetCPClipboardFromLocalText(CPClipboard *clip,
-                                     utf16_t *bufIn);
+                                     const utf16_t *bufIn);
 Bool DnD_SetCPClipboardAndTruncateLocalText(CPClipboard *clip,
                                             utf16_t *bufIn);
 Bool DnD_SetCPClipboardFromLocalRtf(CPClipboard *clip,
index 849c6699dc84dcd5ad12c17857315d0fe7ec487e..fcde5fd283a1faee4dcb6b0499bac428d07db40a 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (C) 2007-2021 VMware, Inc. All rights reserved.
+ * Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -690,7 +691,8 @@ CPClipboard_Serialize(const CPClipboard *clip, // IN
  *
  * Side effects:
  *      The clip passed in should be empty, otherwise will cause memory leakage.
- *      On success, arguments found in buf are unserialized into clip.
+ *      On success, arguments found in buf are unserialized into clip, which
+ *      must be destroyed by calling CPClipboard_Destroy.
  *
  *----------------------------------------------------------------------------
  */
index 6c2d085934eec1656d4c30e031eb28b569a3c944..427e2a21d621beefb25571edc1236ea531414178 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (c) 2007-2019, 2023 VMware, Inc. All rights reserved.
+ * Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -360,9 +361,9 @@ DnDMsg_Serialize(DnDMsg *msg,   // IN/OUT: the message
  */
 
 DnDMsgErr
-DnDMsg_UnserializeHeader(DnDMsg *msg,   // IN/OUT: the message
-                         void *buf,     // IN: the input buffer
-                         size_t len)    // IN: the buffer length
+DnDMsg_UnserializeHeader(DnDMsg *msg,     // IN/OUT: the message
+                         const void *buf, // IN: the input buffer
+                         size_t len)      // IN: the buffer length
 {
    BufRead r;
 
@@ -422,7 +423,7 @@ DnDMsg_UnserializeHeader(DnDMsg *msg,   // IN/OUT: the message
 
 DnDMsgErr
 DnDMsg_UnserializeArgs(DnDMsg *msg,     // IN/OUT: the message
-                       void *buf,       // IN: input buffer
+                       const void *buf, // IN: input buffer
                        size_t len)      // IN: buffer length
 {
    uint32 i;
index 3b852c46ba75c3aecf4c0ab3379eea644ab48efd..58d222cdba124e6d8310bedd158cbea97b983f9a 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (c) 2007-2017, 2023 VMware, Inc. All rights reserved.
+ * Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -158,8 +159,8 @@ DynBuf *DnDMsg_GetArg(DnDMsg *msg, uint32 arg);
 Bool DnDMsg_AppendArg(DnDMsg *msg, void *buf, size_t len);
 Bool DnDMsg_Serialize(DnDMsg *msg, DynBuf *buf);
 
-DnDMsgErr DnDMsg_UnserializeHeader(DnDMsg *msg, void *buf, size_t len);
-DnDMsgErr DnDMsg_UnserializeArgs(DnDMsg *msg, void *buf, size_t len);
+DnDMsgErr DnDMsg_UnserializeHeader(DnDMsg *msg, const void *buf, size_t len);
+DnDMsgErr DnDMsg_UnserializeArgs(DnDMsg *msg, const void *buf, size_t len);
 
 #if defined(__cplusplus)
 }  // extern "C"