From: Martin Subject: Small fix for got_path_strip_trailing_slashes To: gameoftrees@openbsd.org Cc: openbsd@academicsolutions.ch Date: Sat, 11 Jan 2020 19:33:43 +0100 Hi there If got init gets called with '/' as path, got_path_strip_trailing_slashes first zeroes the slash and in the next step reads path[-1] as strlen(path) is 0. This patch splits the condition to first check for a path length > 0. Best, Martin diff --git a/lib/path.c b/lib/path.c index fefe29c..19eb091 100644 --- a/lib/path.c +++ b/lib/path.c @@ -393,8 +393,8 @@ got_path_strip_trailing_slashes(char *path) { int x; - while (path[x = strlen(path) - 1] == '/') - path[x] = '\0'; + while ((x = strlen(path)) > 0 && path[x - 1] == '/') + path[x - 1] = '\0'; } /* based on findprog() from usr.sbin/which/which.c */