]> git.ozlabs.org Git - ccan/commitdiff
tools: Fixed unchecked *strrchr in a couple places.
authorJoey Adams <joeyadams3.14159@gmail.com>
Fri, 25 Feb 2011 04:24:36 +0000 (23:24 -0500)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 8 Mar 2011 00:23:47 +0000 (10:53 +1030)
tools/ccan_depends --compile ccan/module (without a trailing slash)
results in a segfault.

tools/ccanlint/compulsory_tests/depends_exist.c
tools/depends.c

index 12eaf021410153c5567ea1abd22a98afa5ba0b51..b6be1f94b91ddd47f50538caa862cc9d511f44ed 100644 (file)
@@ -41,7 +41,8 @@ static void check_depends_exist(struct manifest *m,
        char **deps;
        char *updir = talloc_strdup(m, m->dir);
 
-       *strrchr(updir, '/') = '\0';
+       if (strrchr(updir, '/'))
+               *strrchr(updir, '/') = '\0';
 
        if (safe_mode)
                deps = get_safe_ccan_deps(m, m->dir, true,
index 870f1e49dd7618073a6b97762c799f819698a891..82524da0a256977ac61191f8ebf2b8d689e5eace 100644 (file)
@@ -59,7 +59,8 @@ static char *compile_info(const void *ctx, const char *dir)
                return NULL;
 
        ccandir = talloc_dirname(ctx, dir);
-       *strrchr(ccandir, '/') = '\0';
+       if (strrchr(ccandir, '/'))
+               *strrchr(ccandir, '/') = '\0';
 
        compiled = maybe_temp_file(ctx, "", false, "info");
        if (compile_and_link(ctx, info_c_file, ccandir, "",