Skip to content

Commit bb48326

Browse files
committed
flags.txt: address potential buffer overflow
1 parent 0aad1fe commit bb48326

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nob.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,15 @@ void nob__go_rebuild_urself(int argc, char **argv, const char *source_path, ...)
695695
Nob_String_Builder sb = {0};
696696
if (nob_read_entire_file(nob_flags_file_path, &sb)) {
697697
Nob_String_View sv = nob_sb_to_sv(sb);
698+
nob_da_append(&sb, '\n'); // NOTE: extra new line, just in case
698699
while (sv.count > 0) {
699700
Nob_String_View flag = nob_sv_trim(nob_sv_chop_by_delim(&sv, '\n'));
700-
if (flag.count == 0) continue; // NOTE: ignore empty lines
701+
if (flag.count == 0) continue; // NOTE: ignore empty lines
701702
if (*flag.data == '#') continue; // NOTE: ignore commented out lines
702-
((char*)flag.data)[flag.count] = '\0'; // TODO: explain why this is fine
703+
((char*)flag.data)[flag.count] = '\0'; // NOTE: we always have at least an extra '\n' character
704+
// at the end of each line. So we always have something
705+
// we can safely replace with '\0' to turn the flag into
706+
// a C-string.
703707
nob_cmd_append(&cmd, flag.data);
704708
}
705709
}

0 commit comments

Comments
 (0)