[augeas-devel] src/augtool.c (cleanpath): Don't access path[-1].

Jim Meyering jim at meyering.net
Tue May 20 19:22:48 UTC 2008


I spotted this by inspection.
However, it may not be possible to trigger bad behavior, since
chk_args seems to guard against any zero-length PATH arguments.

Note: this fix violates decl-after-code, so
if you want to accommodate pre-c99 compilers
I'll move the declaration of "e" up.


 ---------------------------
changeset:   479:2183d5688146
tag:         tip
user:        Jim Meyering <meyering at redhat.com>
date:        Sun May 18 10:54:08 2008 +0200
files:       src/augtool.c
description:
* src/augtool.c (cleanpath): Don't access path[-1].


diff --git a/src/augtool.c b/src/augtool.c
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -46,6 +46,8 @@
 char *loadpath = NULL;

 static char *cleanpath(char *path) {
+    if (strlen(path) == 0)
+        return path;
     char *e = path + strlen(path) - 1;
     while (e != path && (*e == SEP || isspace(*e)))
         *e-- = '\0';




More information about the augeas-devel mailing list