aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-07-15 15:36:51 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-07-15 15:36:51 +0100
commit011d43746faf1bb2a6619e1246143724eb253b52 (patch)
tree72533d6368e39645e7d104e35e09ac5bcdc0a407 /sway/config.c
parentFix config buffer overflow and logic (diff)
downloadsway-011d43746faf1bb2a6619e1246143724eb253b52.tar.gz
sway-011d43746faf1bb2a6619e1246143724eb253b52.tar.zst
sway-011d43746faf1bb2a6619e1246143724eb253b52.zip
Add error handling for getting config file size
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sway/config.c b/sway/config.c
index b8c874e6..2c051146 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -561,12 +561,17 @@ static char *expand_line(const char *block, const char *line, bool add_brace) {
561bool read_config(FILE *file, struct sway_config *config) { 561bool read_config(FILE *file, struct sway_config *config) {
562 bool reading_main_config = false; 562 bool reading_main_config = false;
563 char *this_config = NULL; 563 char *this_config = NULL;
564 unsigned long config_size = 0; 564 size_t config_size = 0;
565 if (config->current_config == NULL) { 565 if (config->current_config == NULL) {
566 reading_main_config = true; 566 reading_main_config = true;
567 567
568 fseek(file, 0, SEEK_END); 568 int ret_seek = fseek(file, 0, SEEK_END);
569 config_size = ftell(file); 569 long ret_tell = ftell(file);
570 if (ret_seek == -1 || ret_tell == -1) {
571 wlr_log(WLR_ERROR, "Unable to get size of config file");
572 return false;
573 }
574 config_size = ret_tell;
570 rewind(file); 575 rewind(file);
571 576
572 config->current_config = this_config = calloc(1, config_size + 1); 577 config->current_config = this_config = calloc(1, config_size + 1);