Opened 7 years ago

Closed 6 years ago

#4480 closed bug (fixed)

System.Directory.canonicalizePath gives bad result

Reported by: erikd Owned by: simonmar
Priority: high Milestone: 7.4.1
Component: libraries/directory Version: 7.1
Keywords: Cc:
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Test Case: libraries/directory/tests/T4113
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by igloo)

Running ghci on linux with an empty path gives different wrong results each time:

   Prelude> System.Directory.canonicalizePath []
   "\153\229\228]\170\DEL"
   Prelude> System.Directory.canonicalizePath []
   "\160\147\155\\\170\DEL"
   Prelude> System.Directory.canonicalizePath []
   "\136"

As pointed out by geheimdienst on #haskell:

my speculation is this: canonicalizePath calls realpath, which for "" gives an EINVAL with the result string being undefined. haskell forgets to check errno and takes the undefined string

This bug exists on 6.12.1 on Debian and 6.12.3 on FreeBSD.

Change History (12)

comment:1 Changed 7 years ago by benl

Also broken on Windows

Prelude> canonicalizePath ""
*** Exception: getFullPathName: invalid argument (Error 0x2af4041)
Prelude> canonicalizePath ""
*** Exception: getFullPathName: invalid argument (Error 0x29b7091)

Note the error number changes each time...

comment:2 Changed 7 years ago by benl

Resolution: worksforme
Status: newclosed

Nevermind, look's like it's fixed in the head.

comment:3 Changed 7 years ago by benl

Resolution: worksforme
Status: closednew

I take it back. It's fixed in the head on Linux but not on Windows. Once it even said

Prelude> canonicalizePath ""
*** Exception: getFullPathName: invalid argument (Cannot create another system semaphore.)

comment:4 Changed 7 years ago by benl

Component: Compilerlibraries/directory
Operating System: Unknown/MultipleWindows
Version: 6.12.37.1

comment:5 Changed 7 years ago by igloo

Description: modified (diff)

comment:6 Changed 7 years ago by igloo

Milestone: 7.0.2

I also got this once:

Prelude> System.Directory.canonicalizePath []
*** Exception: getFullPathName: permission denied (The drive cannot find the sector requested.)

Interestingly, the behaviour in a compiled program is consistently:

e.exe: getFullPathName: invalid argument (The operation completed successfully.)

comment:7 Changed 7 years ago by simonmar

See also #4113. I think this works on later versions of Windows (maybe Vista+). It looks like earlier versions of Windows just return 0 from GetFullPathName() but without setting GetLastError().

We already have a test, namely T4113, but it is currently in lib/IO (should be in the directory package instead).

comment:8 Changed 6 years ago by igloo

Milestone: 7.0.27.2.1

comment:9 Changed 6 years ago by igloo

See also #4215, #5014.

comment:10 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:11 Changed 6 years ago by simonmar

difficulty: Unknown
Owner: set to simonmar
Priority: normalhigh

We need to move the test to the right place.

comment:12 Changed 6 years ago by simonmar

Resolution: fixed
Status: newclosed
Test Case: libraries/directory/tests/T4113
Note: See TracTickets for help on using tickets.