Opened 3 years ago

Closed 2 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 Difficulty: Unknown
Test Case: libraries/directory/tests/T4113 Blocked By:
Blocking: Related Tickets:

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 3 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 3 years ago by benl

  • Resolution set to worksforme
  • Status changed from new to closed

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

comment:3 Changed 3 years ago by benl

  • Resolution worksforme deleted
  • Status changed from closed to new

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 3 years ago by benl

  • Component changed from Compiler to libraries/directory
  • Operating System changed from Unknown/Multiple to Windows
  • Version changed from 6.12.3 to 7.1

comment:5 Changed 3 years ago by igloo

  • Description modified (diff)

comment:6 Changed 3 years ago by igloo

  • Milestone set to 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 3 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 3 years ago by igloo

  • Milestone changed from 7.0.2 to 7.2.1

comment:9 Changed 3 years ago by igloo

See also #4215, #5014.

comment:10 Changed 3 years ago by igloo

  • Milestone changed from 7.2.1 to 7.4.1

comment:11 Changed 2 years ago by simonmar

  • Difficulty set to Unknown
  • Owner set to simonmar
  • Priority changed from normal to high

We need to move the test to the right place.

comment:12 Changed 2 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to libraries/directory/tests/T4113
Note: See TracTickets for help on using tickets.