libiberty: avoid reading past end of buffer in strndup/xstrndup (PR c/78498)