gmr1_a5(n, ...) silently fell through the default case for n >= 2, leaving caller-supplied dl/ul buffers uninitialized. The only in-tree caller in src/gmr1_rx.c passes n data-driven (cd->tch3_state.ciph) into a stack buffer ciph[208] at line 500, so a value other than 0 or 1 exposes uninitialized stack memory to gmr1_tch3_decode() as a supposed keystream.
Zero the output buffers in the default case, matching the n=0 'no ciphering' path, so the function's postcondition (buffers are fully written whenever non-NULL) holds for every legal value of n.
No algorithmic change to gmr1_a5_1 or the n=0 / n=1 paths.
Signed-off-by: Dominik Bay eimann@etherkiller.de --- src/l1/a5.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/l1/a5.c b/src/l1/a5.c index ad6ca8f..105dcb2 100644 --- a/src/l1/a5.c +++ b/src/l1/a5.c @@ -71,7 +71,12 @@ gmr1_a5(int n, uint8_t *key, uint32_t fn, int nbits, break;
default: - /* a5/[2...7] not supported/existent */ + /* a5/[2...7] reserved; zero the buffers so callers never + * observe uninitialized memory as keystream. */ + if (dl) + memset(dl, 0x00, nbits); + if (ul) + memset(ul, 0x00, nbits); break; }; }