mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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 commitbcd6b3ec3a) (cherry picked from commit1b64c54b8a)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user