fix memory issue in spandsp_tone_detect

This commit is contained in:
Anthony Minessale committed 2011-06-17 11:51:23 -05:00
1 parent bf2b27a9c2
commit 8793c2ed37
2 files changed
+29 -7

No files matched your search

@@ -173,7 +173,7 @@ static globals_t globals;
*/
#define MAX_TONES 32
#define STRLEN 128
/**
* Tone descriptor
*
@@ -187,7 +187,9 @@ struct tone_descriptor {
super_tone_rx_descriptor_t *spandsp_tone_descriptor;
/** The mapping of tone id to key */
const char *tone_keys[MAX_TONES];
char tone_keys[MAX_TONES][STRLEN];
int idx;
};
typedef struct tone_descriptor tone_descriptor_t;
@@ -256,7 +258,11 @@ static int tone_descriptor_add_tone(tone_descriptor_t *descriptor, const char *k
if (id >= MAX_TONES) {
return -1;
}
descriptor->tone_keys[id] = key;
switch_set_string(descriptor->tone_keys[id], key);
if (id > descriptor->idx) {
descriptor->idx = id;
}
return id;
}
@@ -358,7 +364,8 @@ static switch_bool_t tone_detector_process_buffer(tone_detector_t *detector, voi
{
detector->detected_tone = -1;
super_tone_rx(detector->spandsp_detector, data, len);
if (detector->detected_tone != -1) {
if (detector->detected_tone > -1 && detector->detected_tone < detector->descriptor->idx && detector->detected_tone < MAX_TONES) {
*key = detector->descriptor->tone_keys[detector->detected_tone];
return SWITCH_TRUE;
}