summaryrefslogtreecommitdiffstats
path: root/lib/libexfat.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 10:36:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 10:36:08 +0000
commitf1b69cec3c86b1a52a8cc8980d139105c08518a9 (patch)
tree375566cab235df08966d399e21d0238a0ddc9bd1 /lib/libexfat.c
parentAdding upstream version 1.2.4. (diff)
downloadexfatprogs-f1b69cec3c86b1a52a8cc8980d139105c08518a9.tar.xz
exfatprogs-f1b69cec3c86b1a52a8cc8980d139105c08518a9.zip
Adding upstream version 1.2.5.upstream/1.2.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--lib/libexfat.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/libexfat.c b/lib/libexfat.c
index 9cc184f..6d45358 100644
--- a/lib/libexfat.c
+++ b/lib/libexfat.c
@@ -496,12 +496,20 @@ int exfat_set_volume_label(struct exfat *exfat, char *label_input)
volume_label, sizeof(volume_label));
if (volume_label_len < 0) {
exfat_err("failed to encode volume label\n");
- free(pvol);
- return -1;
+ err = -1;
+ goto out;
}
- memcpy(pvol->vol_label, volume_label, volume_label_len);
pvol->vol_char_cnt = volume_label_len/2;
+ err = exfat_check_name(volume_label, pvol->vol_char_cnt);
+ if (err != pvol->vol_char_cnt) {
+ exfat_err("volume label contain invalid character(%c)\n",
+ le16_to_cpu(label_input[err]));
+ err = -1;
+ goto out;
+ }
+
+ memcpy(pvol->vol_label, volume_label, volume_label_len);
loc.parent = exfat->root;
loc.file_offset = filter.out.file_offset;
@@ -509,6 +517,7 @@ int exfat_set_volume_label(struct exfat *exfat, char *label_input)
err = exfat_add_dentry_set(exfat, &loc, pvol, dcount, false);
exfat_info("new label: %s\n", label_input);
+out:
free(pvol);
return err;
@@ -759,7 +768,7 @@ int exfat_show_volume_serial(int fd)
goto free_ppbr;
}
- exfat_info("volume serial : 0x%x\n", ppbr->bsx.vol_serial);
+ exfat_info("volume serial : 0x%x\n", le32_to_cpu(ppbr->bsx.vol_serial));
free_ppbr:
free(ppbr);
@@ -919,6 +928,8 @@ int exfat_set_fat(struct exfat *exfat, clus_t clus, clus_t next_clus)
exfat->bs->bsx.sect_size_bits;
offset += sizeof(clus_t) * clus;
+ next_clus = cpu_to_le32(next_clus);
+
if (exfat_write(exfat->blk_dev->dev_fd, &next_clus, sizeof(next_clus),
offset) != sizeof(next_clus))
return -EIO;
@@ -1058,3 +1069,22 @@ int exfat_parse_ulong(const char *s, unsigned long *out)
return 0;
}
+
+static inline int check_bad_utf16_char(unsigned short w)
+{
+ return (w < 0x0020) || (w == '*') || (w == '?') || (w == '<') ||
+ (w == '>') || (w == '|') || (w == '"') || (w == ':') ||
+ (w == '/') || (w == '\\');
+}
+
+int exfat_check_name(__le16 *utf16_name, int len)
+{
+ int i;
+
+ for (i = 0; i < len; i++) {
+ if (check_bad_utf16_char(le16_to_cpu(utf16_name[i])))
+ break;
+ }
+
+ return i;
+}