Filenames in VFAT that are exact multiples of 13 are not
null-terminated; handle that particular subcase.
Reported-by: Gert Hulselmans <gerth@zytor.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
+#include <dprintf.h>
#include <stdio.h>
#include <string.h>
#include <sys/dirent.h>
static bool vfat_match_longname(const char *str, const uint16_t *match,
int len)
{
- unsigned char c;
+ unsigned char c = -1; /* Nonzero: we have not yet seen NUL */
uint16_t cp;
- while (len--) {
- cp = *match++;
+ while (len && (cp = *match)) {
+ match++;
+ len--;
c = *str++;
if (cp != codepage.uni[0][c] && cp != codepage.uni[1][c])
return false;
break;
}
- if (c)
+ /*
+ * If the filename is an exact multiple of 13, we have not yet
+ * consumed the final null byte... make sure the next thing in the
+ * pattern string really is a null byte.
+ */
+ if (c && *str)
return false;
/* Any padding entries must be FFFF */