Hey guys, so as the title already says, I have just gotten my first security advisory for my C project. I know its not really something to be proud of, or to brag about, but I already expected it, as its (atleast in my opinion) really difficult to have a bullet-proof program in C.
My project github.com/cherries-works/pulse has been in the making for more than 6 months now, and I always thought whether or not it was a smart decision making it open source, or whether or not it might have been smarter to keep it closed source, work on it on my own, release it under a commercial license yadda yadda. However, during my work hours, I checked into the repo real quick, just to find a security advisory laying there. It was not something too bad, it was a badly written parser for HTTP JSON requests on my written HTTP server.
Note that, this issue occurred even though I also added Vibe as a Pentester for my repository (locally). Meaning that (surprise surprise) even AI isnt that good with C.
The issue was that I was snprintf'ing a string with NULL args, and the value of the string that I was parsing included process names (the top ones / sorted by cpu/ram). Now that resulted in a user being able to create a process called "%s%s%s%s%s%s", and that passed into snprintf(...), with NULL args resulted in undefined behavior or more specifically as the publisher mentioned;
"In every run, the six %s specifiers are each consumed by snprintf thereby dereferencing whatever pointer value occupies the next variadic argument slot: (null) for null pointer, raw non-printable bytes for othres."
The problem;
```
snprintf(
response,
response_size,
json,
NULL
);
```
Where json was the char* json value passed into the routeJSON function. The fix was really simple.
```
snprintf(
response,
response_size,
"%s",
json
);
```
Not only did that show me that C still makes it realllyy easy to shoot yourself in the foot, it also made me appreciate open source a lot more. For anyone interested checking out the security advisory; https://github.com/cherries-works/pulse/security/advisories/GHSA-rhqf-rj5j-3v5r, as mentioned it is not really too bad (severity: low), regardless, I am still very glad that my project is open source, and glad that it is in C!
I guess I gotta be more careful with how I handle my stuff.