Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions INSPECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Code Inspection
The structure of the code is clear, the function names suggest its purpose and makes it a readable code.

The code is modular and separated in different files based on the functionality of the task like reading header, filter and filtering.

Improvements:

1. It is always better to gracefully handle errors rather than panicing, so the UX doesn't break.
2. There should be tests, so including tests would help the user to understand the working of code and check for its robustness.
3. If something is must, then const should be used in order to access them across the code faster.
4. The files which opens should always be closed, so calling a destructor would be better using RAII pattern.
12 changes: 7 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

#include "seccomp.h"

int main(int argc, char **argv) {
if (argc != 2) {
int main(int argc, char **argv)
{
if (argc != 2)
{
die("needs seccomp profile as first argument");
}

struct sock_fprog prog_allow = { 0 };
struct sock_fprog prog_allow = {0};
struct sc_seccomp_file_header hdr = {0};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Initializing the sc_seccomp_file_header struct with = {0} ensures all fields start with known values.


const char *profile_path = argv[1];
FILE *file = sc_must_read_and_validate_header_from_file(profile_path, &hdr);
FILE *file = sc_must_read_and_validate_header_from_file(profile_path, &hdr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the implementation of sc_must_read_and_validate_header_from_file()?
Does it actually validate the header magic bytes?
Does it validate the version?
Does it handle partial reads correctly?

sc_must_read_filter_from_file(file, hdr.len_filter, &prog_allow);


sc_apply_seccomp_filter(&prog_allow);
fclose(file);
}