diff options
author | Alice Frosi <afrosi@redhat.com> | 2023-04-20 16:43:45 +0200 |
---|---|---|
committer | Alice Frosi <afrosi@redhat.com> | 2023-04-21 11:59:21 +0200 |
commit | 3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e (patch) | |
tree | ae1082dd7b10b16e97daad6281314f00a0d35446 | |
parent | 13f5fce51b3644e24a8bd8b86b80c91e8af7ac13 (diff) | |
download | seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar.gz seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar.bz2 seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar.lz seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar.xz seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.tar.zst seitan-3cce68f2a2710fa86c2f0b263ba212a4a3cd4b2e.zip |
Add op_cmp type
-rw-r--r-- | common/gluten.h | 10 | ||||
-rw-r--r-- | operations.c | 20 |
2 files changed, 25 insertions, 5 deletions
diff --git a/common/gluten.h b/common/gluten.h index 8370cf5..eb965d9 100644 --- a/common/gluten.h +++ b/common/gluten.h @@ -108,10 +108,20 @@ struct op_copy_args { struct copy_arg args[6]; }; +enum op_cmp_type { + CMP_EQ, + CMP_NE, + CMP_GT, + CMP_GE, + CMP_LT, + CMP_LE, +}; + struct op_cmp { uint16_t s1_off; uint16_t s2_off; size_t size; + enum op_cmp_type cmp; unsigned int jmp; }; diff --git a/operations.c b/operations.c index 39867b7..6e8d157 100644 --- a/operations.c +++ b/operations.c @@ -252,6 +252,19 @@ static void set_inject_fields(uint64_t id, void *data, const struct op *a, resp->newfd_flags = 0; } +static int op_cmp(void *data, const struct op_cmp *c) +{ + enum op_cmp_type cmp = c->cmp; + int res = memcmp((uint16_t *)data + c->s1_off, + (uint16_t *)data + c->s2_off, c->size); + if ((res == 0 && (cmp == CMP_EQ || cmp == CMP_LE || cmp == CMP_GE)) || + (res < 0 && (cmp == CMP_LT || cmp == CMP_LE)) || + (res > 0 && (cmp == CMP_GT || cmp == CMP_GE))) + return c->jmp; + else + return -1; +} + int do_operations(void *data, struct op operations[], struct seccomp_notif *req, unsigned int n_operations, int notifyfd) { @@ -342,11 +355,8 @@ int do_operations(void *data, struct op operations[], struct seccomp_notif *req, case OP_END: return 0; case OP_CMP: - if (memcmp((uint16_t *)data + operations[i].cmp.s1_off, - (uint16_t *)data + operations[i].cmp.s2_off, - operations[i].cmp.size) != 0) { - i = operations[i].cmp.jmp; - } + if ((ret = op_cmp(data, &operations[i].cmp)) != -1) + i = ret; break; case OP_RESOLVEDFD: ret = resolve_fd(data, &operations[i].resfd, req->pid); |