Skip to content

Commit

Permalink
Allow NUL and \\.\NUL in paths specified as command line arguments (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 4, 2023
1 parent 6c5dec2 commit 33453dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Src/PatchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void CPatchDlg::OnOK()
}
if (selectCount == 1)
{
bool file1Ok = (paths::DoesPathExist(m_file1) != paths::DOES_NOT_EXIST);
bool file2Ok = (paths::DoesPathExist(m_file2) != paths::DOES_NOT_EXIST);
bool file1Ok = (paths::DoesPathExist(m_file1) != paths::DOES_NOT_EXIST) || paths::IsNullDeviceName(m_file1);
bool file2Ok = (paths::DoesPathExist(m_file2) != paths::DOES_NOT_EXIST) || paths::IsNullDeviceName(m_file2);

if (!file1Ok || !file2Ok)
{
Expand Down
9 changes: 7 additions & 2 deletions Src/diffutils/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,11 @@ static int const primes[] =
0
};

static int isnulldev(const char* filename)
{
return (_stricmp(filename, "NUL") == 0 || _stricmp(filename, "\\\\.\\NUL") == 0);
}

/* Given a vector of two file_data objects, read the file associated
with each one, and build the table of equivalence classes.
Return 1 if either file appears to be a binary file.
Expand Down Expand Up @@ -1033,8 +1038,8 @@ read_files (struct file_data filevec[], int pretend_binary, int *bin_file)

// Are both files Open and Regular (no Pipes, Directories, Devices (except NUL))
if (filevec[0].desc < 0 || filevec[1].desc < 0 ||
(!(S_ISREG (filevec[0].stat.st_mode)) && strcmp(filevec[0].name, "NUL") != 0) ||
(!(S_ISREG (filevec[1].stat.st_mode)) && strcmp(filevec[1].name, "NUL") != 0))
(!(S_ISREG (filevec[0].stat.st_mode)) && !isnulldev(filevec[0].name)) ||
(!(S_ISREG (filevec[1].stat.st_mode)) && !isnulldev(filevec[1].name)))
{
assert(!S_ISCHR(filevec[0].stat.st_mode));
assert(!S_ISCHR(filevec[1].stat.st_mode));
Expand Down

0 comments on commit 33453dd

Please sign in to comment.