Skip to content

Commit 2d259dd

Browse files
SCFrenchrocallahan
authored andcommitted
Fix bugs when passing long filenames to open_memory_file()
1 parent 1e272a1 commit 2d259dd

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/EmuFs.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ std::string make_temp_name(const string& orig_path, dev_t orig_device,
7777
stringstream name;
7878
name << "rr-emufs-" << getpid() << "-dev-" << orig_device
7979
<< "-inode-" << orig_inode << "-" << orig_path;
80-
return name.str().substr(0, 255);
80+
// The linux man page for memfd_create says the length limit for the name
81+
// argument is 249 bytes, evidently because it prepends "memfd:" to the
82+
// parameter before using it.
83+
return name.str().substr(0, 249);
8184
}
8285

8386
/*static*/ EmuFile::shr_ptr EmuFile::create(EmuFs& owner,

src/util.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,14 +1551,14 @@ static void replace_char(string& s, char c, char replacement) {
15511551
static ScopedFd create_tmpfs_file(const string &real_name) {
15521552
std::string name = real_name;
15531553
replace_char(name, '/', '\\');
1554-
name = tmp_dir() + real_name;
1554+
name = string(tmp_dir()) + '/' + name;
15551555
name = name.substr(0, 255);
15561556

15571557
ScopedFd fd =
15581558
open(name.c_str(), O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0700);
15591559
/* Remove the fs name so that we don't have to worry about
15601560
* cleaning up this segment in error conditions. */
1561-
unlink(real_name.c_str());
1561+
unlink(name.c_str());
15621562
return fd;
15631563
}
15641564

0 commit comments

Comments
 (0)