Bug 2140566

Summary: /usr/bin/which fails for long path
Product: Red Hat Enterprise Linux 8 Reporter: Pradeep Jagtap <prjagtap>
Component: whichAssignee: Than Ngo <than>
Status: VERIFIED --- QA Contact: CS System Management SST QE <rhel-cs-system-management-subsystem-qe>
Severity: low Docs Contact: Šárka Jana <sjanderk>
Priority: unspecified    
Version: 8.6CC: efedin, than
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: which-2.21-20.el8 Doc Type: Bug Fix
Doc Text:
the bug is triggered when user executes the 'which' command in directory with very long path and the consequence is that 'which' aborts with error "Can't get current working directory" To fix this issue it is use PATH_MAX instead hardcoded 256
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pradeep Jagtap 2022-11-07 09:30:27 UTC
Description of problem:
=======================
/usr/bin/which fails for long path

Version-Release number of selected component (if applicable):
which-2.21-17.el8.x86_64

How reproducible:
====================
Steps to Reproduce:
-------------------
1. Create Directory with long path
      # mkdir -p /tmp/1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000/1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000/11111111112222222222333333333344444444445555555555

2. Change directory to the created one
     # cd !$

3. Execute which command 
     # which cd

Actual results:
=================
Fails with error:
Can't get current working directory

Expected results:
===================
Should show below results
$ which cd
/usr/bin/cd


Additional info:
=================
In RHEL 7,8 and 9)
-------------------
The buffer is 256 in which.c

static char home[256];
static char cwd[256];
  static char result[256];