Codebase list alsa-lib / 38a3909
test: correct emulation for channel-map TLV Current implementation of channel-map TLV on test program is not valid. Furthermore, it brings buffer-over-run due to byte counting. This commit fixes it. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de> Takashi Sakamoto authored 6 years ago Takashi Iwai committed 6 years ago
1 changed file(s) with 17 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
125125 static int allocate_int_elem_set_tlv(struct elem_set_trial *trial,
126126 unsigned int **tlv)
127127 {
128 unsigned int len, pos;
128 unsigned int count, pos;
129129 unsigned int i, j;
130130 struct chmap_entry *entry;
131131
132132 /* Calculate size of TLV packet for channel-mapping information. */
133 len = 0;
133 count = 0;
134134 for (i = 1; i <= 25; ++i) {
135 len += sizeof(struct chmap_entry);
136 len += i * sizeof(unsigned int);
137 }
138
139 *tlv = malloc(len);
140 if (*tlv == NULL)
135 count += 2; /* sizeof(struct chmap_entry). */
136 count += i; /* struct chmap_entry.maps. */
137 }
138
139 *tlv = malloc((2 + count) * sizeof(unsigned int));
140 if (!*tlv)
141141 return -ENOMEM;
142142
143143 /*
144144 * Emulate channel-mapping information in in-kernel implementation.
145145 * Here, 25 entries are for each different channel.
146146 */
147 pos = 0;
148 for (i = 1; i <= 25 && pos < len; ++i) {
147 (*tlv)[0] = SNDRV_CTL_TLVT_CONTAINER;
148 (*tlv)[1] = count * sizeof(unsigned int);
149 pos = 2;
150
151 for (i = 1; i <= 25 && pos < count; ++i) {
149152 entry = (struct chmap_entry *)&(*tlv)[pos];
153
150154 entry->type = SNDRV_CTL_TLVT_CHMAP_FIXED;
151155 entry->length = i * sizeof(unsigned int);
156 pos += 2;
157
152158 for (j = 0; j < i; ++j)
153159 entry->maps[j] = SND_CHMAP_MONO + j;
154 pos += sizeof(struct chmap_entry) + i * sizeof(unsigned int);
160 pos += i;
155161 }
156162
157163 return 0;