Fix out-of-bounds read in serialno matching logic