lib: xpc: fix overlapping variable uses in xpc_string_t

This commit is contained in:
2026-03-21 10:52:23 +00:00
parent 81b9e7777a
commit 8236f99aef
2 changed files with 19 additions and 29 deletions

View File

@@ -18,7 +18,7 @@
.s_flags = XPC_STRING_F_OUT | XPC_STRING_F_REMOTE, \
.s_origin = (msg), \
.s_offset = (offset), \
.s_len = (size), \
.s_max = (size), \
}
struct xpc_msg;
@@ -41,25 +41,19 @@ typedef enum xpc_string_flags {
typedef struct xpc_string {
xpc_string_flags_t s_flags;
union {
struct {
/* only valid if F_OUT is set. specifies the maximum
* number of chars that can be written to s_buf,
* including the null terminator. */
size_t s_max;
/* only valid if F_OUT is set.
* if F_FREE_ON_DISCARD is set, must be either NULL or
* allocated via xpc_context_alloc */
const char *s_buf;
};
/* only valid if F_OUT is set. specifies the maximum
* number of chars that can be written to s_buf,
* including the null terminator. */
size_t s_max;
/* only valid if F_OUT is set.
* if F_FREE_ON_DISCARD is set, must be either NULL or
* allocated via xpc_context_alloc */
const char *s_buf;
struct {
/* only valid if F_IN is set. offset of the string data
* within the associated message. used when reading
* string data from a message. */
size_t s_offset;
};
};
/* valid for F_IN and F_OUT. offset of the string data
* within the associated message. used when reading
* string data from a message. */
size_t s_offset;
/* only valid if F_REMOTE is set.
* used to read/write string data from/to the sender's address space. */

View File

@@ -47,14 +47,10 @@ xpc_status_t xpc_string_write(
to_write = s->s_max - 1;
}
kern_status_t status
= xpc_msg_write(s->s_origin, s->s_offset, in, to_write);
if (status != KERN_OK) {
return status;
}
/* TODO */
*nr_written = to_write;
return KERN_OK;
return xpc_msg_write(
s->s_origin,
s->s_offset,
in,
to_write,
nr_written);
}