fix null deref and packet length check (off by 1)