[physfs] [patch] fix off-by-one in findBinaryInPath()

Dmitry Marakasov amdmi3 at amdmi3.ru
Tue Jul 16 09:17:07 EDT 2013


Hi!

I've sent this to Ryan, but got no reply, so reposting to the list.

findBinaryInPath() has an off-by-one error which makes it produce
incorrect path. For example, for "/usr/local/bin/hedgewars" it will
return "/usr/local/bin/h" instead of "/usr/local/bin/". This happens
because `size` is buffer (not a string) length, so an extra byte
should be substracted to get correct position of binary name.

The problem shows itself on e.g. FreeBSD where procfs is not (always)
mounted, so findBinaryInPath() is used instead of reading procfs.

--- physfs.patch begins here ---
diff -r e0dbcd5e50b9 src/platform_unix.c
--- a/src/platform_unix.c	Fri Nov 30 14:37:37 2012 -0500
+++ b/src/platform_unix.c	Tue Jul 16 17:11:34 2013 +0400
@@ -193,7 +193,7 @@
 
         if (access(exe, X_OK) == 0)  /* Exists as executable? We're done. */
         {
-            exe[size - binlen] = '\0'; /* chop off filename, leave '/' */
+            exe[size - binlen - 1] = '\0'; /* chop off filename, leave '/' */
             return exe;
         } /* if */
 
--- physfs.patch ends here ---

-- 
Dmitry Marakasov   .   55B5 0596 FF1E 8D84 5F56  9510 D35A 80DD F9D2 F77D
amdmi3 at amdmi3.ru  ..:  jabber: amdmi3 at jabber.ru    http://www.amdmi3.ru


More information about the physfs mailing list