Skip to contentSkip to conversation

PATH_MAX + 1 in realpath_not_final()

DISCUSSION Petr Lautrbach 1 participant 1 message Sep 7, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello,

I was asked whether is there a reason for "Resolved path must be a path of size PATH_MAX + 1" in the comment assigned to real_path_not_final() in selinux.h [1]?

/* Resolve all of the symlinks and relative portions of a pathname, but NOT
* the final component (same a realpath() unless the final component is a
* symlink. Resolved path must be a path of size PATH_MAX + 1 */
extern int realpath_not_final(const char *name, char *resolved_path);

Looking into libselinux/src/matchpathcon.c:

 423 │   len = strlen(p);                     
 424 │   if (len + strlen(last_component) + 2 > PATH_MAX) {
 425 │   │   myprintf("symlink_realpath(%s) failed: Filename too long \n",
 426 │   │   │ name);                   
 427 │   │   errno = ENAMETOOLONG;               
 428 │   │   rc = -1;                  
 429 │   │   goto out;                  
 430 │   }

it seems to be that PATH_MAX should be enough? Am I missing something?

[1] https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/selinux.h#L493

Thanks,

Petr