diff --git a/smallapp/unbound-checkconf.c b/smallapp/unbound-checkconf.c index 7acc0865b..83f84aafe 100644 --- a/smallapp/unbound-checkconf.c +++ b/smallapp/unbound-checkconf.c @@ -248,18 +248,18 @@ fname_after_chroot(const char* fname, struct config_file* cfg, int use_chdir) } else if(cfg->directory && cfg->directory[0]) { /* prepend chdir */ if(slashit && cfg->directory[0] != '/') - strncat(buf, "/", sizeof(buf)-1); + strncat(buf, "/", sizeof(buf)-strlen(buf)-1); if(strncmp(cfg->chrootdir, cfg->directory, strlen(cfg->chrootdir)) == 0) strncat(buf, cfg->directory+strlen(cfg->chrootdir), - sizeof(buf)-1); - else strncat(buf, cfg->directory, sizeof(buf)-1); + sizeof(buf)-strlen(buf)-1); + else strncat(buf, cfg->directory, sizeof(buf)-strlen(buf)-1); slashit = 1; } /* fname */ if(slashit && fname[0] != '/') - strncat(buf, "/", sizeof(buf)-1); - strncat(buf, fname, sizeof(buf)-1); + strncat(buf, "/", sizeof(buf)-strlen(buf)-1); + strncat(buf, fname, sizeof(buf)-strlen(buf)-1); buf[sizeof(buf)-1] = 0; return buf; } @@ -329,9 +329,9 @@ morechecks(struct config_file* cfg, char* fname) if(fname[0] != '/') { if(getcwd(buf, sizeof(buf)) == NULL) fatal_exit("getcwd: %s", strerror(errno)); - strncat(buf, "/", sizeof(buf)); + strncat(buf, "/", sizeof(buf)-strlen(buf)-1); } - strncat(buf, fname, sizeof(buf)); + strncat(buf, fname, sizeof(buf)-strlen(buf)-1); if(strncmp(buf, cfg->chrootdir, strlen(cfg->chrootdir)) != 0) fatal_exit("config file %s is not inside chroot %s", buf, cfg->chrootdir);