From 733eb99b1773452f11318d856ed4f1008f1bf8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 10 Aug 2014 13:51:41 +0200 Subject: [PATCH] script: fix potential crash in case of malloc error --- src/plugins/script/script-repo.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/script/script-repo.c b/src/plugins/script/script-repo.c index a3e6d7cd7..bd6d5105b 100644 --- a/src/plugins/script/script-repo.c +++ b/src/plugins/script/script-repo.c @@ -174,22 +174,22 @@ script_repo_get_filename_loaded (struct t_script_repo *script) weechat_home = weechat_info_get ("weechat_dir", NULL); length = strlen (weechat_home) + strlen (script->name_with_extension) + 64; filename = malloc (length); - if (filename) + if (!filename) + return NULL; + + snprintf (filename, length, "%s/%s/autoload/%s", + weechat_home, + script_language[script->language], + script->name_with_extension); + if (stat (filename, &st) != 0) { - snprintf (filename, length, "%s/%s/autoload/%s", + snprintf (filename, length, "%s/%s/%s", weechat_home, script_language[script->language], script->name_with_extension); if (stat (filename, &st) != 0) { - snprintf (filename, length, "%s/%s/%s", - weechat_home, - script_language[script->language], - script->name_with_extension); - if (stat (filename, &st) != 0) - { - filename[0] = '\0'; - } + filename[0] = '\0'; } }