aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
-rw-r--r--gluten.h2
-rw-r--r--operations.c19
-rw-r--r--tests/unit/test_operations.c13
3 files changed, 22 insertions, 12 deletions
diff --git a/gluten.h b/gluten.h
index 57b53ad..699d682 100644
--- a/gluten.h
+++ b/gluten.h
@@ -97,7 +97,7 @@ struct op_inject {
struct copy_arg {
uint16_t args_off;
- bool need_copied;
+ enum value_type type;
size_t size;
};
diff --git a/operations.c b/operations.c
index cd67ccc..6b19212 100644
--- a/operations.c
+++ b/operations.c
@@ -169,15 +169,18 @@ int copy_args(struct seccomp_notif *req, struct op_copy_args *copy, void *data,
fprintf(stderr, "the seccomp request isn't valid anymore\n");
return -1;
}
-
for (i = 0; i < 6; i++) {
- if (!copy->args[i].need_copied)
- continue;
- dest = (uint16_t *)data + copy->args[i].args_off;
- nread = pread(fd, dest, copy->args[i].size, req->data.args[i]);
- if (nread < 0) {
- perror("pread");
- return -1;
+ if (copy->args[i].type == REFERENCE) {
+ dest = (uint16_t *)data + copy->args[i].args_off;
+ nread = pread(fd, dest, copy->args[i].size,
+ req->data.args[i]);
+ if (nread < 0) {
+ perror("pread");
+ return -1;
+ }
+ } else {
+ memcpy((uint16_t *)data + copy->args[i].args_off,
+ &req->data.args[i], copy->args[i].size);
}
}
close(fd);
diff --git a/tests/unit/test_operations.c b/tests/unit/test_operations.c
index 4bcca57..2d1a6a9 100644
--- a/tests/unit/test_operations.c
+++ b/tests/unit/test_operations.c
@@ -416,16 +416,19 @@ START_TEST(test_op_copy)
};
struct op_copy_args *o = &operations[0].copy;
struct sockaddr_un *addr;
+ socklen_t *len, expect;
int ret;
- o->args[0] = (struct copy_arg){ .args_off = 0, .size = sizeof(int) };
+ o->args[0] = (struct copy_arg){ .args_off = 0,
+ .type = IMMEDIATE,
+ .size = sizeof(int) };
o->args[1] =
(struct copy_arg){ .args_off = sizeof(int) / sizeof(uint16_t),
- .need_copied = true,
+ .type = REFERENCE,
.size = sizeof(struct sockaddr_un) };
o->args[2] = (struct copy_arg){ .args_off = o->args[1].args_off /
sizeof(uint16_t),
- .need_copied = false,
+ .type = IMMEDIATE,
.size = sizeof(socklen_t) };
ret = do_operations(&tmp_data, operations, &req,
sizeof(operations) / sizeof(operations[0]), -1,
@@ -435,6 +438,10 @@ START_TEST(test_op_copy)
addr = (struct sockaddr_un *)(tmp_data + o->args[1].args_off);
ck_assert_str_eq(addr->sun_path, "/tmp/test.sock");
ck_assert(addr->sun_family == AF_UNIX);
+ expect = sizeof(addr->sun_path);
+ len = (socklen_t *)(tmp_data + o->args[2].args_off);
+ ck_assert_msg(*len == expect, "expect len %x to be equal to %x", *len,
+ expect);
}
END_TEST