Correct truncation detection after use of snprintf: The case where

exactly one character was truncated was not detected.
This commit is contained in:
Jacques Vidrine 2003-12-17 13:36:05 +00:00
parent 37fc1cc08e
commit cd9607fdd9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=123602
2 changed files with 5 additions and 5 deletions

View File

@ -159,7 +159,7 @@ extract_plist(const char *home, Package *pkg)
PUSHOUT(Directory);
}
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
if (add_count < 0 || add_count > maxargs - perm_count) {
if (add_count < 0 || add_count >= maxargs - perm_count) {
cleanup(0);
errx(2, "%s: oops, miscounted strings!", __func__);
}
@ -179,7 +179,7 @@ extract_plist(const char *home, Package *pkg)
PUSHOUT(Directory);
}
add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
if (add_count < 0 || add_count > maxargs - where_count) {
if (add_count < 0 || add_count >= maxargs - where_count) {
cleanup(0);
errx(2, "%s: oops, miscounted strings!", __func__);
}
@ -187,7 +187,7 @@ extract_plist(const char *home, Package *pkg)
add_count = snprintf(&perm_args[perm_count],
maxargs - perm_count,
"'%s' ", p->name);
if (add_count < 0 || add_count > maxargs - perm_count) {
if (add_count < 0 || add_count >= maxargs - perm_count) {
cleanup(0);
errx(2, "%s: oops, miscounted strings!", __func__);
}

View File

@ -204,7 +204,7 @@ copy_plist(const char *home, Package *plist)
p->name);
last_chdir = home;
}
if (add_count < 0 || add_count > maxargs - where_count) {
if (add_count < 0 || add_count >= maxargs - where_count) {
cleanup(0);
errx(2, "%s: oops, miscounted strings!", __func__);
}
@ -242,7 +242,7 @@ copy_plist(const char *home, Package *plist)
" -C %s %s",
mythere ? mythere : where,
p->name);
if (add_count < 0 || add_count > maxargs - where_count) {
if (add_count < 0 || add_count >= maxargs - where_count) {
cleanup(0);
errx(2, "%s: oops, miscounted strings!", __func__);
}