diff options
author | Marvin Borner | 2021-04-01 19:39:14 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-01 19:39:14 +0200 |
commit | afa00abb2b68205bee539d7947130d6b1b1ec6e9 (patch) | |
tree | 3a821a75af6c4d4ff1bd4128c4859d77abf87e66 /apps | |
parent | 4c168fb34c15a1b8981abef7ccef1542a6fb05ca (diff) |
Hardened entire system
By using the nonnull attribute and replace buffer-overflow-prone
functions like strcpy, strcat and sprintf by strlcpy, strlcat and
snprintf.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/chess.c | 10 | ||||
-rw-r--r-- | apps/test.c | 1 | ||||
-rw-r--r-- | apps/wm.c | 4 |
3 files changed, 7 insertions, 8 deletions
diff --git a/apps/chess.c b/apps/chess.c index 6670919..833edb0 100644 --- a/apps/chess.c +++ b/apps/chess.c @@ -58,7 +58,7 @@ static vec2 selected = { -1, -1 }; // Selected tile static void load_image(struct piece *tile) { char icon[48] = { 0 }; - sprintf(icon, "/icons/chess-%s-%d.png", tile->name, TILE); + snprintf(icon, sizeof(icon), "/icons/chess-%s-%d.png", tile->name, TILE); enum gfx_filter filter = IS_COLOR(tile->piece, BLACK) ? GFX_FILTER_NONE : GFX_FILTER_INVERT; /* assert(gui_fill(win, tile->widget, GUI_LAYER_FG, 0) == EOK); */ @@ -87,7 +87,7 @@ static void mouseclick(u32 widget_id, vec2 pos) clicked_piece->piece = selected_piece->piece; selected_piece->piece = 0; - strcpy(clicked_piece->name, selected_piece->name); + strlcpy(clicked_piece->name, selected_piece->name, sizeof(clicked_piece->name)); selected_piece->name[0] = '\0'; /* assert(gui_fill(win, selected_piece->widget, GUI_LAYER_FG, 0) == EOK); */ @@ -102,7 +102,7 @@ static void mouseclick(u32 widget_id, vec2 pos) } } -static const char *resolve_name(u32 piece, char *buf) +static const char *resolve_name(u32 piece, char buf[8]) { const char *name = NULL; switch (piece & TYPE_MASK) { @@ -128,7 +128,7 @@ static const char *resolve_name(u32 piece, char *buf) err(1, "Unknown piece %d\n", piece); } - strcpy(buf, name); + strlcpy(buf, name, 8); return buf; } @@ -204,7 +204,7 @@ static void fen_parse(const char *fen) u32 piece = fen_resolve_letter(*p); tiles[x][y].piece = piece; - resolve_name(piece, (char *)&tiles[x][y].name); + resolve_name(piece, tiles[x][y].name); x++; } diff --git a/apps/test.c b/apps/test.c index 18d9f8b..8c6dedc 100644 --- a/apps/test.c +++ b/apps/test.c @@ -79,7 +79,6 @@ TEST(mem) EQUALS(memcmp(str2, str4, strlen(str2)), -1); EQUALS(memcmp(str2, str3, strlen(str2)), 0); EQUALS(memcmp(str0, str1, strlen(str0)), 0); - EQUALS(memcmp(NULL, NULL, 0), 0); char buf[6] = { 0 }; EQUALS_STR(memcpy(buf, "hallo", 6), "hallo"); @@ -388,7 +388,7 @@ static void handle_message_redraw_window(struct message_redraw_window *msg) struct window *win = window_find(id); if (!win || win->client.pid != msg->header.src) { if (msg->header.state == MSG_NEED_ANSWER) - msg_send(msg->header.src, GUI_REDRAW_WINDOW | MSG_FAILURE, NULL, + msg_send(msg->header.src, GUI_REDRAW_WINDOW | MSG_FAILURE, msg, sizeof(msg->header)); return; } @@ -406,7 +406,7 @@ static void handle_message_destroy_window(struct message_destroy_window *msg) struct window *win = window_find(id); if (!win || win->client.pid != msg->header.src) { if (msg->header.state == MSG_NEED_ANSWER) - msg_send(msg->header.src, GUI_DESTROY_WINDOW | MSG_FAILURE, NULL, + msg_send(msg->header.src, GUI_DESTROY_WINDOW | MSG_FAILURE, msg, sizeof(msg->header)); return; } |