Skip to content
Snippets Groups Projects
  • Arkadiusz Hiler's avatar
    a7001318
    tests/tools_test: Use readlink() properly · a7001318
    Arkadiusz Hiler authored
    Turns out that `readlink()` does not NULL-terminate the string and since
    it resides on the stack we may end up with some junk:
    
      `/proc/self/exe point to /opt/igt/libexec/igt-gpu-tools/tools_test7<CD>\t<8A>^?`
    
    That in turn confuses `dirname()` and we end up doing `chdir("/")`,
    which explain the sporadic failures of this test where it was not able
    to locate the tools.
    
    Let's zero out the variable first and allow `readlink()` to write at
    most `sizeof()-1` bytes to it, so it is always properly terminated.
    
    Cc: Petri Latvala <petri.latvala@intel.com>
    Cc: Tomi Sarvela <tomi.p.sarvela@intel.com>
    Issue: #12
    
    
    Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
    Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
    a7001318
    History
    tests/tools_test: Use readlink() properly
    Arkadiusz Hiler authored
    Turns out that `readlink()` does not NULL-terminate the string and since
    it resides on the stack we may end up with some junk:
    
      `/proc/self/exe point to /opt/igt/libexec/igt-gpu-tools/tools_test7<CD>\t<8A>^?`
    
    That in turn confuses `dirname()` and we end up doing `chdir("/")`,
    which explain the sporadic failures of this test where it was not able
    to locate the tools.
    
    Let's zero out the variable first and allow `readlink()` to write at
    most `sizeof()-1` bytes to it, so it is always properly terminated.
    
    Cc: Petri Latvala <petri.latvala@intel.com>
    Cc: Tomi Sarvela <tomi.p.sarvela@intel.com>
    Issue: #12
    
    
    Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
    Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>