sxhkd-rc

[fork] simple X hotkey daemon (but for the rc shell)
Log | Files | Refs | README | LICENSE

commit 3d70f57823b06944a8e2d4b51b685b6b7de74b40
parent c6c1d7c7e1249e449215a79ab50697277864fcf4
Author: Bastien Dejean <nihilhill@gmail.com>
Date:   Sat, 21 Sep 2013 15:24:56 +0200

Make sure strings are null-terminated

Diffstat:
Mparse.c | 17+++++++----------
Msxhkd.c | 2+-
Mtypes.c | 4++--
3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/parse.c b/parse.c @@ -2362,9 +2362,9 @@ void load_config(char *config_file) *(end + 1) = '\0'; if (isgraph(first)) - strncpy(chain + offset, start, sizeof(chain) - offset); + snprintf(chain + offset, sizeof(chain) - offset, "%s", start); else - strncpy(command + offset, start, sizeof(command) - offset); + snprintf(command + offset, sizeof(command) - offset, "%s", start); if (*end == PARTIAL_LINE) { offset += end - start; @@ -2417,9 +2417,9 @@ void process_hotkey(char *hotkey_string, char *command_string) chunk_t *hk_chunks = extract_chunks(hotkey_string); chunk_t *cm_chunks = extract_chunks(command_string); if (hk_chunks == NULL) - strncpy(hotkey, hotkey_string, sizeof(hotkey)); + snprintf(hotkey, sizeof(hotkey), "%s", hotkey_string); if (cm_chunks == NULL) - strncpy(command, command_string, sizeof(command)); + snprintf(command, sizeof(command), "%s", command_string); render_next(hk_chunks, hotkey); render_next(cm_chunks, command); @@ -2638,10 +2638,8 @@ bool parse_chain(char *string, chain_t *chain) event_type = key_to_button(event_type); chord_t *c = make_chord(keysym, button, modfield, event_type, replay_event, lock_chain); add_chord(chain, c); - if (status_fifo != NULL) { - strncpy(c->repr, chord, sizeof(c->repr)); - c->repr[strlen(chord)] = '\0'; - } + if (status_fifo != NULL) + snprintf(c->repr, sizeof(c->repr), "%s", chord); keysym = XCB_NO_SYMBOL; button = XCB_NONE; modfield = 0; @@ -2718,8 +2716,7 @@ bool parse_modifier(char *name, uint16_t *modfield) bool parse_fold(char *string, char *folded_string) { if (strchr(string, SEQ_BEGIN) != NULL && strrchr(string, SEQ_END) != NULL) { - strncpy(folded_string, string, strlen(string)); - folded_string[strlen(string)] = '\0'; + snprintf(folded_string, strlen(string), "%s", string); return true; } return false; diff --git a/sxhkd.c b/sxhkd.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) else snprintf(config_file, sizeof(config_file), "%s/%s/%s", getenv("HOME"), ".config", CONFIG_PATH); } else { - strncpy(config_file, config_path, sizeof(config_file)); + snprintf(config_file, sizeof(config_file), "%s", config_path); } if (fifo_path != NULL) { diff --git a/types.c b/types.c @@ -17,7 +17,7 @@ hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfiel if (match_chord(c->state, event_type, keysym, button, modfield)) { if (status_fifo != NULL && num_active == 0) { if (!chained) { - strncpy(progress, c->state->repr, sizeof(progress)); + snprintf(progress, sizeof(progress), "%s", c->state->repr); } else { strncat(progress, LNK_SEP, sizeof(progress) - strlen(progress) - 1); strncat(progress, c->state->repr, sizeof(progress) - strlen(progress) - 1); @@ -146,7 +146,7 @@ hotkey_t *make_hotkey(chain_t *chain, char *command) { hotkey_t *hk = malloc(sizeof(hotkey_t)); hk->chain = chain; - strncpy(hk->command, command, sizeof(hk->command)); + snprintf(hk->command, sizeof(hk->command), "%s", command); hk->next = NULL; return hk; }