diff --git a/src/args.c b/src/args.c index 6dbe2a3..dc710bf 100644 --- a/src/args.c +++ b/src/args.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -105,8 +106,8 @@ void args_parse(Parameters *params, int argc, char **argv) { char *arg; char *value; - strncpy(params->project_path, DATADIR "/default", STR_LEN); - strncpy(params->config_file, "forge_project.cfg", STR_LEN); + strlcpy(params->project_path, DATADIR "/default", STR_LEN); + strlcpy(params->config_file, "forge_project.cfg", STR_LEN); params->hot_reload = false; params->output = true; params->output_screen = 0; @@ -119,7 +120,7 @@ void args_parse(Parameters *params, int argc, char **argv) { params->video_in.length = 0; params->video_size = 0; params->internal_size = 720; - strncpy(params->state_file, "forge_saved_state.txt", STR_LEN); + strlcpy(params->state_file, "forge_saved_state.txt", STR_LEN); params->load_state = true; params->save_state = true; params->trace_midi = false; @@ -134,9 +135,9 @@ void args_parse(Parameters *params, int argc, char **argv) { puts(PACKAGE " " VERSION); exit(EXIT_SUCCESS); } else if (is_arg(arg, "-p") || is_arg(arg, "--project")) { - strncpy(params->project_path, value, STR_LEN); + strlcpy(params->project_path, value, STR_LEN); } else if (is_arg(arg, "-c") || is_arg(arg, "--config")) { - strncpy(params->config_file, value, STR_LEN); + strlcpy(params->config_file, value, STR_LEN); } else if (is_arg(arg, "-hr") || is_arg(arg, "--hot-reload")) { params->hot_reload = true; } else if (is_arg(arg, "-s") || is_arg(arg, "--screen")) { @@ -165,7 +166,7 @@ void args_parse(Parameters *params, int argc, char **argv) { log_error("maximum video input reached"); exit(EXIT_FAILURE); } - strncpy(params->video_in.values[params->video_in.length++], value, + strlcpy(params->video_in.values[params->video_in.length++], value, STR_LEN); } else if (is_arg(arg, "-vs") || is_arg(arg, "--video-size")) { params->video_size = parse_uint(arg, value); @@ -178,7 +179,7 @@ void args_parse(Parameters *params, int argc, char **argv) { invalid_value(arg, value); } } else if (is_arg(arg, "-sf") || is_arg(arg, "--state-file")) { - strncpy(params->state_file, value, STR_LEN); + strlcpy(params->state_file, value, STR_LEN); } else if (is_arg(arg, "-ls") || is_arg(arg, "--load-state")) { params->load_state = true; } else if (is_arg(arg, "-nls") || is_arg(arg, "--no-load-state")) { diff --git a/src/config_file.c b/src/config_file.c index db4e2e6..ca4cfe5 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -52,11 +53,11 @@ static void parse_config_file_line(ConfigFile *config, char *line) { key_size = equal_pos - line; value_size = size - key_size - 1; - strncpy(item.key, line, key_size); + strlcpy(item.key, line, key_size + 1); item.key[key_size] = '\0'; if (value_size > 0) { - strncpy(item.value, line + key_size + 1, value_size); + strlcpy(item.value, line + key_size + 1, value_size + 1); item.value[value_size] = '\0'; } @@ -90,7 +91,7 @@ char *config_file_get_str(ConfigFile *config, char *key, char *default_value) { ConfigFileItem c_key; ConfigFileItem *item; - strncpy(c_key.key, key, STR_LEN); + strlcpy(c_key.key, key, STR_LEN); item = (ConfigFileItem *)hashmap_get(config->map, &c_key); @@ -106,7 +107,7 @@ unsigned int config_file_get_int(ConfigFile *config, char *key, ConfigFileItem c_key; ConfigFileItem *item; - strncpy(c_key.key, key, STR_LEN); + strlcpy(c_key.key, key, STR_LEN); item = (ConfigFileItem *)hashmap_get(config->map, &c_key); diff --git a/src/file.c b/src/file.c index 36fd0c0..1c5696e 100644 --- a/src/file.c +++ b/src/file.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -68,7 +69,7 @@ bool file_update(File *file) { } void file_read(File *file, char *path) { - strncpy(file->path, path, STR_LEN); + strlcpy(file->path, path, STR_LEN); file->content = NULL; file->error = false; file->last_write = 0; diff --git a/src/midi.c b/src/midi.c index 5463ac7..2fa5fda 100644 --- a/src/midi.c +++ b/src/midi.c @@ -1,5 +1,6 @@ #include #include +#include #include "types.h" @@ -7,7 +8,7 @@ #include "log.h" void midi_open(MidiDevice *device, char *name) { - strncpy(device->name, name, STR_LEN); + strlcpy(device->name, name, STR_LEN); device->input = NULL; device->output = NULL; diff --git a/src/project.c b/src/project.c index 43d53da..c41044c 100644 --- a/src/project.c +++ b/src/project.c @@ -80,7 +80,7 @@ void project_init(Project *project, char *project_path, char *config_file) { char *frag_prefix; unsigned int i; - strncpy(project->path, project_path, STR_LEN); + strlcpy(project->path, project_path, STR_LEN); snprintf(config_path, STR_LEN, "%s/%s", project_path, config_file); diff --git a/src/string.c b/src/string.c index 1e5a420..631ec46 100644 --- a/src/string.c +++ b/src/string.c @@ -63,8 +63,8 @@ char *string_replace_at(char *src, unsigned int from, unsigned int to, dst = malloc(src_len - (to - from) + rpl_len + 1); - strncpy(dst, src, from); - strncpy(dst + from, rpl, rpl_len); + strlcpy(dst, src, from + 1); + strlcpy(dst + from, rpl, rpl_len + 1); strlcpy(dst + from + rpl_len, src + to, src_len - to + 1); return dst; diff --git a/src/video.c b/src/video.c index 433f3cb..1399039 100644 --- a/src/video.c +++ b/src/video.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -66,7 +67,7 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation, } static void open_device(VideoCapture *video_capture, char *name) { - strncpy(video_capture->name, name, STR_LEN); + strlcpy(video_capture->name, name, STR_LEN); video_capture->error = false; video_capture->fd = -1; video_capture->exp_fd = -1;