Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: use correct buf size in cancd
- X-seq: zsh-workers 54599
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: use correct buf size in cancd
- Date: Sat, 23 May 2026 08:37:09 +0200
- Archived-at: <https://zsh.org/workers/54599>
- List-id: <zsh-workers.zsh.org>
When path is metafied, it can be longer than PATH_MAX, so use MAXCMDLEN.
Using ztrlen >= PATH_MAX instead of strlen >= MAXCMDLEN is just a minor
optimization to avoid the syscall if we know the path is too long anyway,
but it's not worth doing this extra check on the result of the snprintf
call (probably).
---
Src/exec.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Src/exec.c b/Src/exec.c
index f5c5e8e077..62f9310fad 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -6417,7 +6417,7 @@ cancd(char *s)
char *t;
if (*s != '/') {
- char sbuf[PATH_MAX+1], **cp;
+ char sbuf[MAXCMDLEN], **cp;
if (cancd2(s))
return s;
@@ -6426,9 +6426,9 @@ cancd(char *s)
if (!nocdpath)
for (cp = cdpath; *cp; cp++) {
if (**cp) {
- if (snprintf(sbuf, PATH_MAX, "%s/%s", *cp, s) >= PATH_MAX)
+ if (snprintf(sbuf, sizeof(sbuf), "%s/%s", *cp, s) >= sizeof(sbuf))
continue;
- } else if (strlen(s) >= PATH_MAX) {
+ } else if (ztrlen(s) >= PATH_MAX) {
continue;
} else {
strcpy(sbuf, s);
--
2.38.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author