Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix null-terminated string bug in serialize_dirent64() and deserializ…
…e_dirent64() Summary: I was trying to get hermit to work for `mkfs.ext3` when I kept running into a peculiar error. It seem like when we run `mkfs` with hermit, we successfully create the partition, but it fails to perform some sort of clean up task: P1201825018 Looking at the ASAN bug trace, it seems like the offender is this line: https://www.internalfb.com/phabricator/paste/view/P1201825018?lines=25 This brings us to this line: https://www.internalfb.com/code/fbsource/[83ba118d4900598aaa2adc4befd8b09450225915]/fbcode/hermetic_infra/hermit/detcore/src/dirents.rs?lines=101-105 In the `readdir` [man page](https://man7.org/linux/man-pages/man3/readdir.3.html), it states that the name is *null-terminated*: ``` struct dirent { ino_t d_ino; /* Inode number */ off_t d_off; /* Not an offset; see below */ unsigned short d_reclen; /* Length of this record */ unsigned char d_type; /* Type of file; not supported by all filesystem types */ char d_name[256]; /* Null-terminated filename */ }; ``` Moreover, it seems that there is an explicit callout against using the length or `sizeof()` methods to identify the size of this character: > Warning: applications should avoid any dependence on the size of > the d_name field. POSIX defines it as char d_name[], a character > array of unspecified size, with at most NAME_MAX characters > preceding the terminating null byte ('\0'). A fix for this should be, then, to just use `strlen()` unless I'm mistaken Reviewed By: wangbj Differential Revision: D55495680 fbshipit-source-id: c428260b41079d8a50e37628aadd12ee49036d72
- Loading branch information