diff options
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r-- | res/res_musiconhold.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 004934676..fd61cb7a8 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -513,7 +513,10 @@ static int spawn_mp3(struct mohclass *class) ast_close_fds_above_n(STDERR_FILENO); /* Child */ - chdir(class->dir); + if (chdir(class->dir) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + _exit(1); + } if (ast_test_flag(class, MOH_CUSTOM)) { execv(argv[0], argv); } else { @@ -917,8 +920,8 @@ static int moh_scan_files(struct mohclass *class) { if (class->dir[0] != '/') { ast_copy_string(dir_path, ast_config_AST_VAR_DIR, sizeof(dir_path)); - strncat(dir_path, "/", sizeof(dir_path)); - strncat(dir_path, class->dir, sizeof(dir_path)); + strncat(dir_path, "/", sizeof(dir_path) - 1); + strncat(dir_path, class->dir, sizeof(dir_path) - 1); } else { ast_copy_string(dir_path, class->dir, sizeof(dir_path)); } @@ -934,8 +937,14 @@ static int moh_scan_files(struct mohclass *class) { class->total_files = 0; dirnamelen = strlen(dir_path) + 2; - getcwd(path, sizeof(path)); - chdir(dir_path); + if (!getcwd(path, sizeof(path))) { + ast_log(LOG_WARNING, "getcwd() failed: %s\n", strerror(errno)); + return -1; + } + if (chdir(path) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + return -1; + } while ((files_dirent = readdir(files_DIR))) { /* The file name must be at least long enough to have the file type extension */ if ((strlen(files_dirent->d_name) < 4)) @@ -972,7 +981,10 @@ static int moh_scan_files(struct mohclass *class) { } closedir(files_DIR); - chdir(path); + if (chdir(path) < 0) { + ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno)); + return -1; + } if (ast_test_flag(class, MOH_SORTALPHA)) qsort(&class->filearray[0], class->total_files, sizeof(char *), moh_sort_compare); return class->total_files; |