aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
-rw-r--r--operations.c58
1 files changed, 53 insertions, 5 deletions
diff --git a/operations.c b/operations.c
index cfb3a9c..33596aa 100644
--- a/operations.c
+++ b/operations.c
@@ -546,10 +546,59 @@ int op_bitwise(const struct seccomp_notif *req, int notifier, struct gluten *g,
return 0;
}
+static void str_offset_value(const struct seccomp_notif *req, struct gluten *g,
+ const struct gluten_offset *offset, size_t size,
+ char *v, size_t s_str)
+{
+ const void *px = gluten_ptr(&req->data, g, *offset);
+ char t[PATH_MAX];
+
+ if(!px) {
+ err(" empty gluten to read");
+ return;
+ }
+
+ switch(offset->type) {
+ case OFFSET_NULL:
+ snprintf(v, s_str, "offset %d is NULL", offset->offset);
+ return;
+ case OFFSET_SECCOMP_DATA:
+ snprintf(t, PATH_MAX, "%llx", *(long long unsigned *)px);
+ goto print;
+ case OFFSET_INSTRUCTION:
+ snprintf(v, s_str, "offset %d to instruction", offset->offset);
+ return;
+ case OFFSET_METADATA:
+ snprintf(t, PATH_MAX, "%s", metadata_type_str[*(unsigned int *)px]);
+ goto print;
+ default:
+ break;
+ }
+ switch(size) {
+ case sizeof(unsigned int):
+ snprintf(t, PATH_MAX,"%x", *(unsigned int *)px);
+ goto print;
+ case sizeof(long unsigned):
+ snprintf(t, PATH_MAX,"%lx", *(long unsigned*)px);
+ goto print;
+ default:
+ /* For the cases where it isn't possible to have a nice print, just print
+ * the type and offset
+ */
+ snprintf(v, s_str, "(type=%s offset=%d) size=%ld", gluten_offset_name[offset->type],
+ offset->offset, size);
+ return;
+ }
+print:
+ snprintf(v, s_str, "(type=%s offset=%d)='%s'", gluten_offset_name[offset->type],
+ offset->offset, t);
+}
+
int op_cmp(const struct seccomp_notif *req, int notifier, struct gluten *g,
struct op_cmp *op)
{
const struct cmp_desc *desc = gluten_ptr(&req->data, g, op->desc);
+ char str_x[PATH_MAX], str_y[PATH_MAX];
enum op_cmp_type cmp;
const void *px, *py;
int res;
@@ -567,10 +616,9 @@ int op_cmp(const struct seccomp_notif *req, int notifier, struct gluten *g,
!check_gluten_limits(desc->x, desc->size) ||
!check_gluten_limits(desc->y, desc->size))
return -1;
-
- debug(" op_cmp: operands x=(%s %d) y=(%s %d) size=%d",
- gluten_offset_name[desc->x.type], desc->x.offset,
- gluten_offset_name[desc->y.type], desc->y.offset, desc->size);
+ str_offset_value(req, g, &desc->x, desc->size, str_x, PATH_MAX);
+ str_offset_value(req, g, &desc->y, desc->size, str_y, PATH_MAX);
+ debug(" op_cmp: operands x=%s y=%s", str_x, str_y);
res = memcmp(px, py, desc->size);
@@ -624,7 +672,7 @@ int op_nr(const struct seccomp_notif *req, int notifier, struct gluten *g,
if (gluten_read(NULL, g, &nr, op->nr, sizeof(nr)) == -1)
return -1;
- debug(" op_nr: checking syscall=%ld", nr);
+ debug(" op_nr: checking syscall %s", syscall_name_str[nr]);
if (nr == req->data.nr)
return 0;