r/C_Programming • u/xerrs_ • Jun 20 '26
Project Pulse, my very first C only project
I have been teaching myself systems programming over the past year by building software in C, and I just released the first public version of one of my projects: Pulse.
a lightweight Linux monitoring dashboard that:
- reads system metrics directly /proc
- serves a web interface using its own HTTP server
- has minimal dependencies
- is written entirely in C
The goal wasnt to build another Grafana replacement (cuz what the hell), but to create something small, understandable, and easy to run.
This is the first public release (v0.1.0), so Im mainly looking for feedback from people who use Linux or enjoy systems programming.
would love to know:
- What would stop you from using it?
- Is the codebase easy to navigate?
- Are there metrics you'd expect to see?
- Any obvious design mistakes?
Repository: https://github.com/cherries-works/pulse
I'm happy to answer questions about the implementation or discuss why I made certain design decisions. (I learned C less than a month ago, this is how I try to improve my knowledge, so be nice to me please lol)
•
u/AutoModerator Jun 20 '26
Hi /u/xerrs_,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
8
u/CompilerChicken Jun 22 '26
If you are teaching yourself C please please please do not use AI it will only hinder you. Its quite obvious that AI was heavily used, just looking at the commit history
2
u/traxplayer Jun 21 '26
Does it compile with -Wall -Werror ?
2
u/skeeto Jun 21 '26
Looks slick! The web interface is a nice, novel touch. Consider testing with sanitizers:
-fsanitize=address,undefined. There are multiple memory errors, in no small part due to unsigned arithmetic and null terminated strings, error prone practices that are unnecessary even if common. Also consider using-Wextra, which statically catches some of these issues, and-Wvlaso you can fix those accidental VLAs.I've got precise set of fixes here you can harvest in whatever way you see fit (too large to inline them all here anyway):
https://github.com/skeeto/pulse/commits/main/?author=skeeto
It includes a switch to a (faster, simpler) unity build, which made my analysis easier, and which you may or may not care about.
First, I had trouble building due to incorrect
externdeclarations (UB):There's an immediate, guaranteed buffer overflow on every run. There's a strange extra out-of-bounds
freadwith no purpose, the code advanced thebufferparameter itself without tracking size changes, plus some general lack of error handling (all buffer overflows):There's a buffer overflow in
trim.end >= 0is always true (unsigned), so the bounds check is a no-op; on all-space or empty inputendwrapped to UINT_MAX. The subsequentend - start(used as the copy length and as the final null-terminator index) then also overflows, producing unbounded out-of-bounds writes. The scan also started atbuffer[size], one beyond the last character.In
parseUptimethe copy loop is bounded only byi < size(size is the full buffer length, ~2048) while writing into a fixedchar number[16], so any input longer than 15 bytes before the first space overflowed the stack. The buffer was also never null-terminated before atoi(), soatoicould read past the written bytes.In
getCputhe per-character accumulation wrote into a fixedchar number[16]with no bound onnumber_index, overflowing the stack on any field longer than 15 characters. The buffer was also not reliably null-terminated before atoi(), so atoi could read stale/garbage bytes past the current token.Three problems parsing the
/proc/diskstatsline:char *next = strchr(line, ' '); *next = '\0';dereferenced the result with no null check, crashing on a truncated line / final field.line = next + 1the code didread = atoi(line), parsing the field after the one at index i instead of the matched field. Capture the token before advancing.atoi()truncates to 32-bit signed, but the Disk struct fields are unsigned long long. Usestrtoull().getLoaddereferenced each strchr() result (*next = '\0') without a NULL check, so a short or empty /proc/loadavg (e.g. when the read failed) crashed the program. Guard each lookup and leave missing fields at 0.In getNetwork(), the per-field tokenizer did not null check. The last of the 8 transmit columns on each interface line is terminated by '\n', not a space, so strchr(line, ' ') would scan into the next line or return null at end of buffer and crash. The header-skip
strchr()calls and the per-line '\n' lookup were likewise unchecked.Each static route (HTML/CSS/JS/image) had the same defects:
file_buffer[size - 1] = '\0'overwrote the last byte of every served file, and underflowed to file_buffer[-1] when fread returned 0.In
serverLaunchunsigned arithmetic promotes read errors (-1) to a huge unsigned value; the buffer was then left unterminated and parsed as a request. A short read falls into the same logic.accept()was given &server->address as the client-address out-parameter, overwriting the server's own bound sockaddr with each client's address on every connection. Use a local clientAddr / socklen_t instead so the server's address state is left intact.1
u/traxplayer Jun 21 '26
Maybe typedef struct ... ?
1
u/traxplayer Jun 21 '26
Maybe also rewrite your Makefile so it uses globs instead of listing all files for a given target.
-7
u/traxplayer Jun 21 '26
I think it is a bit strange that the headers are in a separate directory.
And consider add a clean target in the Makefile and set it to PHONY
0
u/[deleted] Jun 21 '26
[deleted] — view deleted comment