Avoid a segfault on invalid format names

If a format name was not found by ast_getformatbyname, a NULL pointer
would be passed into ast_format_rate and immediately dereferenced.
This ensures that a valid pointer is used since the structure is
already allocated on the stack.

(closes issue DPH-523)
Reported-by: Steve Pitts


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@374932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kinsey Moore
2012-10-12 21:57:29 +00:00
parent ccf01fbfdc
commit 09dac916ba
+3 -2
View File
@@ -5969,12 +5969,13 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
if ((recording_fs = ast_readfile(recdata->recording_file, recdata->recording_ext, NULL, 0, 0, VOICEMAIL_DIR_MODE))) {
if (!ast_seekstream(recording_fs, 0, SEEK_END)) {
long framelength = ast_tellstream(recording_fs);
struct ast_format result;
struct ast_format result = {0,};
/* XXX This use of ast_getformatbyname seems incorrect here. The file extension does not necessarily correspond
* to the name of the format. For instance, if "raw" were passed in, I don't think ast_getformatbyname would
* find the slinear format
*/
duration = (int) (framelength / ast_format_rate(ast_getformatbyname(recdata->recording_ext, &result)));
ast_getformatbyname(recdata->recording_ext, &result);
duration = (int) (framelength / ast_format_rate(&result));
}
}