diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2004-01-24 02:22:16 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2004-01-24 02:22:16 +0000 |
commit | dcb3b6fc7e87df4dd29089bacdd83db9fdaed872 (patch) | |
tree | 9a002c65461371d903feb2e628cd801a81c8b7e3 /src/common/weeconfig.c | |
parent | 16717f83227219be59a252f89db94172d7ff8f0d (diff) | |
download | weechat-dcb3b6fc7e87df4dd29089bacdd83db9fdaed872.zip |
Secured code to prevent buffer overflows and memory leaks
Diffstat (limited to 'src/common/weeconfig.c')
-rw-r--r-- | src/common/weeconfig.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 4ec27c6a4..3f92af312 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -754,15 +754,20 @@ config_default_values () int config_read () { + int filename_length; char *filename; FILE *file; int section, line_number, i, option_number; int server_found; char line[1024], *ptr_line, *pos, *pos2; + filename_length = strlen (weechat_home) + 64; filename = - (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char)); - sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR); + (char *) malloc (filename_length * sizeof (char)); + if (!filename) + return -2; + snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, + weechat_home, DIR_SEPARATOR); if ((file = fopen (filename, "rt")) == NULL) { gui_printf (NULL, _("%s config file \"%s\" not found.\n"), @@ -955,6 +960,7 @@ config_read () int config_create_default () { + int filename_length; char *filename; FILE *file; int i, j; @@ -962,9 +968,13 @@ config_create_default () struct passwd *my_passwd; char *realname, *pos; + filename_length = strlen (weechat_home) + 64; filename = - (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char)); - sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR); + (char *) malloc (filename_length * sizeof (char)); + if (!filename) + return -2; + snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, + weechat_home, DIR_SEPARATOR); if ((file = fopen (filename, "wt")) == NULL) { gui_printf (NULL, _("%s cannot create file \"%s\"\n"), @@ -1111,6 +1121,7 @@ config_create_default () int config_write (char *config_name) { + int filename_length; char *filename; FILE *file; int i, j; @@ -1122,9 +1133,13 @@ config_write (char *config_name) filename = strdup (config_name); else { + filename_length = strlen (weechat_home) + 64; filename = - (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char)); - sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR); + (char *) malloc (filename_length * sizeof (char)); + if (!filename) + return -2; + snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME, + weechat_home, DIR_SEPARATOR); } if ((file = fopen (filename, "wt")) == NULL) |