| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fanalyzer" } */ |
| 3 |
/* { dg-require-effective-target analyzer } */ |
| 4 |
|
| 5 |
/* Reduced from a -Wanalyzer-tainted-array-index false +ve |
| 6 |
seen in the Linux kernel's sound/drivers/opl3/opl3_synth.c. */ |
| 7 |
|
| 8 |
extern unsigned long |
| 9 |
copy_from_user(void* to, const void* from, unsigned long n); |
| 10 |
|
| 11 |
struct sbi_patch |
| 12 |
{ |
| 13 |
unsigned char prog; |
| 14 |
unsigned char bank; |
| 15 |
}; |
| 16 |
struct fm_patch |
| 17 |
{ |
| 18 |
unsigned char prog; |
| 19 |
unsigned char bank; |
| 20 |
struct fm_patch* next; |
| 21 |
}; |
| 22 |
struct snd_opl3 |
| 23 |
{ |
| 24 |
struct fm_patch* patch_table[32]; |
| 25 |
}; |
| 26 |
int |
| 27 |
snd_opl3_load_patch(struct snd_opl3* opl3, |
| 28 |
int prog, |
| 29 |
int bank); |
| 30 |
struct fm_patch* |
| 31 |
snd_opl3_find_patch(struct snd_opl3* opl3, |
| 32 |
int prog, |
| 33 |
int bank, |
| 34 |
int create_patch); |
| 35 |
long |
| 36 |
snd_opl3_write(struct snd_opl3* opl3, |
| 37 |
const char* buf, |
| 38 |
long count) |
| 39 |
{ |
| 40 |
long result = 0; |
| 41 |
int err = 0; |
| 42 |
struct sbi_patch inst; |
| 43 |
while (count >= sizeof(inst)) { |
| 44 |
if (copy_from_user(&inst, buf, sizeof(inst))) |
| 45 |
return -14; |
| 46 |
err = snd_opl3_load_patch(opl3, inst.prog, inst.bank); |
| 47 |
if (err < 0) |
| 48 |
break; |
| 49 |
result += sizeof(inst); |
| 50 |
count -= sizeof(inst); |
| 51 |
} |
| 52 |
return result > 0 ? result : err; |
| 53 |
} |
| 54 |
int |
| 55 |
snd_opl3_load_patch(struct snd_opl3* opl3, |
| 56 |
int prog, |
| 57 |
int bank) |
| 58 |
{ |
| 59 |
struct fm_patch* patch; |
| 60 |
patch = snd_opl3_find_patch(opl3, prog, bank, 1); |
| 61 |
if (!patch) |
| 62 |
return -12; |
| 63 |
return 0; |
| 64 |
} |
| 65 |
struct fm_patch* |
| 66 |
snd_opl3_find_patch(struct snd_opl3* opl3, int prog, int bank, int create_patch) |
| 67 |
{ |
| 68 |
unsigned int key = (prog + bank) % 32; |
| 69 |
struct fm_patch* patch; |
| 70 |
for (patch = opl3->patch_table[key]; patch; patch = patch->next) { /* { dg-bogus "use of attacker-controlled value in array lookup" } */ |
| 71 |
if (patch->prog == prog && patch->bank == bank) |
| 72 |
return patch; |
| 73 |
} |
| 74 |
return ((void*)0); |
| 75 |
} |