libguestfs/SOURCES/0045-generator-Fix-implementation-of-FUUID-for-OCaml-func.patch
2025-05-05 12:29:59 +03:00

45 lines
1.7 KiB
Diff

From af2e259ff72d5a41c9cfe453a67ecff77190cbc6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 16 Apr 2025 13:19:17 +0100
Subject: [PATCH] generator: Fix implementation of FUUID for OCaml functions
This was implemented wrongly. In the XDR protocol, UUIDs are fixed
buffers of length 32. We can just use memcpy to copy from the OCaml
string to the UUID, but we have to ensure the string length returned
by OCaml is correct (if not we just assert, it's an internal error).
(It didn't even compile before, so we know it was never used).
(cherry picked from commit bcd6b3ec3a1038d840e832732b3910f939566436)
(cherry picked from commit 1b64c54b8a7f3a0ada0cc52fc74d800a55318112)
---
generator/daemon.ml | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/generator/daemon.ml b/generator/daemon.ml
index 0218d3e5..d9f22c51 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -611,6 +611,7 @@ let generate_daemon_caml_stubs () =
#include <string.h>
#include <inttypes.h>
#include <errno.h>
+#include <assert.h>
#include <caml/alloc.h>
#include <caml/callback.h>
@@ -646,9 +647,12 @@ let generate_daemon_caml_stubs () =
fun i ->
pr " v = Field (retv, %d);\n" i;
function
- | n, (FString|FDevice|FUUID) ->
+ | n, (FString|FDevice) ->
pr " ret->%s = strdup (String_val (v));\n" n;
pr " if (ret->%s == NULL) return NULL;\n" n
+ | n, FUUID ->
+ pr " assert (caml_string_length (v) == sizeof ret->%s);\n" n;
+ pr " memcpy (ret->%s, String_val (v), sizeof ret->%s);\n" n n
| n, FBuffer ->
pr " ret->%s_len = caml_string_length (v);\n" n;
pr " ret->%s = strdup (String_val (v));\n" n;