diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2018-01-16 09:42:25 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2018-01-16 09:42:25 -0600 |
commit | d677ff47ae04b14fd0c4c5eae2c2ee6926f9e49c (patch) | |
tree | c57750bddbe949e49a095c922f3ca8b074807f82 | |
parent | 9cfdb81e913a8dd363ca4570b4eb4137de3b5837 (diff) | |
parent | de7f2a6cb4c17c1aefa5c71228fa9a299591d92c (diff) |
Merge "res_stasis_recording: Allow symbolic links in configured recordings dir."
-rw-r--r-- | res/stasis_recording/stored.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/res/stasis_recording/stored.c b/res/stasis_recording/stored.c index 9df5d75dc..ac216ff8c 100644 --- a/res/stasis_recording/stored.c +++ b/res/stasis_recording/stored.c @@ -330,6 +330,7 @@ struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name( RAII_VAR(char *, file_with_ext, NULL, ast_free); int res; struct stat file_stat; + int prefix_len = strlen(ast_config_AST_RECORDING_DIR); errno = 0; @@ -350,18 +351,28 @@ struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name( ast_string_field_build(recording, file, "%s/%s", dir, file); if (!ast_begins_with(dir, ast_config_AST_RECORDING_DIR)) { - /* Attempt to escape the recording directory */ - ast_log(LOG_WARNING, "Attempt to access invalid recording %s\n", - name); - errno = EACCES; - return NULL; + /* It's possible that one or more component of the recording path is + * a symbolic link, this would prevent dir from ever matching. */ + char *real_basedir = realpath(ast_config_AST_RECORDING_DIR, NULL); + + if (!real_basedir || !ast_begins_with(dir, real_basedir)) { + /* Attempt to escape the recording directory */ + ast_log(LOG_WARNING, "Attempt to access invalid recording directory %s\n", + dir); + ast_std_free(real_basedir); + errno = EACCES; + + return NULL; + } + + prefix_len = strlen(real_basedir); + ast_std_free(real_basedir); } /* The actual name of the recording is file with the config dir * prefix removed. */ - ast_string_field_set(recording, name, - recording->file + strlen(ast_config_AST_RECORDING_DIR) + 1); + ast_string_field_set(recording, name, recording->file + prefix_len + 1); file_with_ext = find_recording(dir, file); if (!file_with_ext) { |