NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/58306: procfs does not remove dot segments from executable paths



>Number:         58306
>Category:       kern
>Synopsis:       procfs does not remove dot segments from executable paths
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 04 15:00:00 +0000 2024
>Originator:     matyalatte
>Release:        10.0
>Organization:
>Environment:
NetBSD  10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Hi, I'm making cross-platform utilities to get environment information.
https://github.com/matyalatte/c-env-utils

It uses readlink("/proc/curproc/exe", path, PATH_MAX) to get an executable path on NetBSD.
Then, I noticed the function does not remove dot segments when running the binary with a relative path like "./myexe."

I think the exe path should be normalized.
>How-To-Repeat:
1. Compile the following code.

```
// myexe.c
#include <unistd.h>
#include <limits.h>
#include <stdio.h>

int main(void) {
    char path[PATH_MAX];
    readlink("/proc/curproc/exe", path, PATH_MAX);
    printf("exe path: %s", path);
}
```

2. Run it with relative paths

```
$ ./myexe
exe path: /home/myname/myrepo/build/./myexe
$ ../build/myexe
exe path: /home/myname/myrepo/build/../build/myexe
$ ../build/./myexe
exe path: /home/myname/myrepo/build/../build/./myexe
```

3. What I expected

```
$ ./myexe
exe path: /home/myname/myrepo/build/myexe
$ ../build/myexe
exe path: /home/myname/myrepo/build/myexe
$ ../build/./myexe
exe path: /home/myname/myrepo/build/myexe
```
>Fix:



Home | Main Index | Thread Index | Old Index