This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=c4cdb5e104120d3cb70699d122a9c22ea065b2de commit c4cdb5e104120d3cb70699d122a9c22ea065b2de Author: Guillem Jover <[email protected]> AuthorDate: Mon Jul 22 20:20:38 2024 +0200 dpkg: Replace sprintf() usage with a varbuf in depisok() This removes a statically sized stack variable. Changelog: internal --- src/main/depcon.c | 149 +++++++++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 69 deletions(-) diff --git a/src/main/depcon.c b/src/main/depcon.c index 0906d3ed0..f48e2e87b 100644 --- a/src/main/depcon.c +++ b/src/main/depcon.c @@ -310,12 +310,6 @@ depisok(struct dependency *dep, struct varbuf *whynot, struct deppossi *provider; struct pkginfo *pkg_pos; - /* Use this buffer so that when internationalization comes along we - * don't have to rewrite the code completely, only redo the sprintf strings - * (assuming we have the fancy argument-number-specifiers). - * Allow 250x3 for package names, versions, &c, + 250 for ourselves. */ - char linebuf[1024]; - if (dep->type != dep_depends && dep->type != dep_predepends && dep->type != dep_breaks && @@ -374,6 +368,8 @@ depisok(struct dependency *dep, struct varbuf *whynot, /* TODO: Check dep_enhances as well. */ if (dep->type == dep_depends || dep->type == dep_predepends || dep->type == dep_recommends || dep->type == dep_suggests ) { + struct varbuf linebuf = VARBUF_INIT; + /* Go through the alternatives. As soon as we find one that * we like, we return ‘true’ straight away. Otherwise, when we get to * the end we'll have accumulated all the reasons in whynot and @@ -386,22 +382,23 @@ depisok(struct dependency *dep, struct varbuf *whynot, while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) { switch (pkg_pos->clientdata->istobe) { case PKG_ISTOBE_REMOVE: - sprintf(linebuf, _(" %.250s is to be removed.\n"), - pkg_name(pkg_pos, pnaw_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is to be removed.\n"), + pkg_name(pkg_pos, pnaw_nonambig)); break; case PKG_ISTOBE_DECONFIGURE: - sprintf(linebuf, _(" %.250s is to be deconfigured.\n"), - pkg_name(pkg_pos, pnaw_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is to be deconfigured.\n"), + pkg_name(pkg_pos, pnaw_nonambig)); break; case PKG_ISTOBE_INSTALLNEW: if (versionsatisfied(&pkg_pos->available, possi)) { deppossi_pkg_iter_free(possi_iter); + varbuf_destroy(&linebuf); return true; } - sprintf(linebuf, _(" %.250s is to be installed, but is version " - "%.250s.\n"), - pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig), - versiondescribe(&pkg_pos->available.version, vdew_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is to be installed, " + "but is version %.250s.\n"), + pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig), + versiondescribe(&pkg_pos->available.version, vdew_nonambig)); break; case PKG_ISTOBE_NORMAL: case PKG_ISTOBE_PREINSTALL: @@ -410,18 +407,19 @@ depisok(struct dependency *dep, struct varbuf *whynot, case PKG_STAT_TRIGGERSPENDING: if (versionsatisfied(&pkg_pos->installed, possi)) { deppossi_pkg_iter_free(possi_iter); + varbuf_destroy(&linebuf); return true; } - sprintf(linebuf, _(" %.250s is installed, but is version " - "%.250s.\n"), - pkg_name(pkg_pos, pnaw_nonambig), - versiondescribe(&pkg_pos->installed.version, vdew_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is installed, " + "but is version %.250s.\n"), + pkg_name(pkg_pos, pnaw_nonambig), + versiondescribe(&pkg_pos->installed.version, vdew_nonambig)); break; case PKG_STAT_NOTINSTALLED: /* Don't say anything about this yet - it might be a virtual package. * Later on, if nothing has put anything in linebuf, we know that it * isn't and issue a diagnostic then. */ - *linebuf = '\0'; + varbuf_reset(&linebuf); break; case PKG_STAT_TRIGGERSAWAITED: if (canfixbytrigaw && versionsatisfied(&pkg_pos->installed, possi)) @@ -431,42 +429,44 @@ depisok(struct dependency *dep, struct varbuf *whynot, case PKG_STAT_HALFCONFIGURED: if (allowunconfigd) { if (!dpkg_version_is_informative(&pkg_pos->configversion)) { - sprintf(linebuf, _(" %.250s is unpacked, but has never been " - "configured.\n"), - pkg_name(pkg_pos, pnaw_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is unpacked, " + "but has never been configured.\n"), + pkg_name(pkg_pos, pnaw_nonambig)); break; } else if (!versionsatisfied(&pkg_pos->installed, possi)) { - sprintf(linebuf, _(" %.250s is unpacked, but is version " - "%.250s.\n"), - pkg_name(pkg_pos, pnaw_nonambig), - versiondescribe(&pkg_pos->installed.version, - vdew_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s is unpacked, " + "but is version %.250s.\n"), + pkg_name(pkg_pos, pnaw_nonambig), + versiondescribe(&pkg_pos->installed.version, + vdew_nonambig)); break; } else if (!dpkg_version_relate(&pkg_pos->configversion, possi->verrel, &possi->version)) { - sprintf(linebuf, _(" %.250s latest configured version is " - "%.250s.\n"), - pkg_name(pkg_pos, pnaw_nonambig), - versiondescribe(&pkg_pos->configversion, vdew_nonambig)); + varbuf_set_fmt(&linebuf, _(" %.250s latest configured " + "version is %.250s.\n"), + pkg_name(pkg_pos, pnaw_nonambig), + versiondescribe(&pkg_pos->configversion, + vdew_nonambig)); break; } else { deppossi_pkg_iter_free(possi_iter); + varbuf_destroy(&linebuf); return true; } } /* Fall through. */ default: - sprintf(linebuf, _(" %.250s is %s.\n"), - pkg_name(pkg_pos, pnaw_nonambig), - gettext(statusstrings[pkg_pos->status])); + varbuf_set_fmt(&linebuf, _(" %.250s is %s.\n"), + pkg_name(pkg_pos, pnaw_nonambig), + gettext(statusstrings[pkg_pos->status])); break; } break; default: internerr("unknown istobe depended '%d'", pkg_pos->clientdata->istobe); } - varbuf_add_str(whynot, linebuf); + varbuf_add_varbuf(whynot, &linebuf); } deppossi_pkg_iter_free(possi_iter); @@ -477,8 +477,10 @@ depisok(struct dependency *dep, struct varbuf *whynot, if (provider->up->type != dep_provides) continue; if (!pkg_virtual_deppossi_satisfied(possi, provider)) continue; - if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW) + if (provider->up->up->clientdata->istobe == PKG_ISTOBE_INSTALLNEW) { + varbuf_destroy(&linebuf); return true; + } } /* Now look at the packages already on the system. */ @@ -497,41 +499,47 @@ depisok(struct dependency *dep, struct varbuf *whynot, * information above. */ continue; case PKG_ISTOBE_REMOVE: - sprintf(linebuf, _(" %.250s provides %.250s but is to be removed.\n"), - pkg_name(provider->up->up, pnaw_nonambig), - possi->ed->name); + varbuf_set_fmt(&linebuf, _(" %.250s provides %.250s " + "but is to be removed.\n"), + pkg_name(provider->up->up, pnaw_nonambig), + possi->ed->name); break; case PKG_ISTOBE_DECONFIGURE: - sprintf(linebuf, _(" %.250s provides %.250s but is to be deconfigured.\n"), - pkg_name(provider->up->up, pnaw_nonambig), - possi->ed->name); + varbuf_set_fmt(&linebuf, _(" %.250s provides %.250s " + "but is to be deconfigured.\n"), + pkg_name(provider->up->up, pnaw_nonambig), + possi->ed->name); break; case PKG_ISTOBE_NORMAL: case PKG_ISTOBE_PREINSTALL: if (provider->up->up->status == PKG_STAT_INSTALLED || - provider->up->up->status == PKG_STAT_TRIGGERSPENDING) + provider->up->up->status == PKG_STAT_TRIGGERSPENDING) { + varbuf_destroy(&linebuf); return true; + } if (provider->up->up->status == PKG_STAT_TRIGGERSAWAITED) *canfixbytrigaw = provider->up->up; - sprintf(linebuf, _(" %.250s provides %.250s but is %s.\n"), - pkg_name(provider->up->up, pnaw_nonambig), - possi->ed->name, - gettext(statusstrings[provider->up->up->status])); + varbuf_set_fmt(&linebuf, _(" %.250s provides %.250s but is %s.\n"), + pkg_name(provider->up->up, pnaw_nonambig), + possi->ed->name, + gettext(statusstrings[provider->up->up->status])); break; default: internerr("unknown istobe provider '%d'", provider->up->up->clientdata->istobe); } - varbuf_add_str(whynot, linebuf); + varbuf_add_varbuf(whynot, &linebuf); } - if (!*linebuf) { + if (linebuf.used == 0) { /* If the package wasn't installed at all, and we haven't said * yet why this isn't satisfied, we should say so now. */ - sprintf(linebuf, _(" %.250s is not installed.\n"), possi->ed->name); - varbuf_add_str(whynot, linebuf); + varbuf_set_fmt(&linebuf, _(" %.250s is not installed.\n"), + possi->ed->name); + varbuf_add_varbuf(whynot, &linebuf); } } + varbuf_destroy(&linebuf); return false; } else { @@ -562,10 +570,12 @@ depisok(struct dependency *dep, struct varbuf *whynot, case PKG_ISTOBE_INSTALLNEW: if (!versionsatisfied(&pkg_pos->available, possi)) break; - sprintf(linebuf, _(" %.250s (version %.250s) is to be installed.\n"), - pkgbin_name(pkg_pos, &pkg_pos->available, pnaw_nonambig), - versiondescribe(&pkg_pos->available.version, vdew_nonambig)); - varbuf_add_str(whynot, linebuf); + varbuf_add_fmt(whynot, _(" %.250s (version %.250s) is " + "to be installed.\n"), + pkgbin_name(pkg_pos, &pkg_pos->available, + pnaw_nonambig), + versiondescribe(&pkg_pos->available.version, + vdew_nonambig)); if (!canfixbyremove) { deppossi_pkg_iter_free(possi_iter); return false; @@ -594,11 +604,12 @@ depisok(struct dependency *dep, struct varbuf *whynot, case PKG_STAT_TRIGGERSAWAITED: if (!versionsatisfied(&pkg_pos->installed, possi)) break; - sprintf(linebuf, _(" %.250s (version %.250s) is present and %s.\n"), - pkg_name(pkg_pos, pnaw_nonambig), - versiondescribe(&pkg_pos->installed.version, vdew_nonambig), - gettext(statusstrings[pkg_pos->status])); - varbuf_add_str(whynot, linebuf); + varbuf_add_fmt(whynot, _(" %.250s (version %.250s) is " + "present and %s.\n"), + pkg_name(pkg_pos, pnaw_nonambig), + versiondescribe(&pkg_pos->installed.version, + vdew_nonambig), + gettext(statusstrings[pkg_pos->status])); if (!canfixbyremove) { deppossi_pkg_iter_free(possi_iter); return false; @@ -625,10 +636,10 @@ depisok(struct dependency *dep, struct varbuf *whynot, continue; /* Conflicts and provides the same. */ if (!pkg_virtual_deppossi_satisfied(possi, provider)) continue; - sprintf(linebuf, _(" %.250s provides %.250s and is to be installed.\n"), - pkgbin_name(provider->up->up, &provider->up->up->available, - pnaw_nonambig), possi->ed->name); - varbuf_add_str(whynot, linebuf); + varbuf_add_fmt(whynot, _(" %.250s provides %.250s and is " + "to be installed.\n"), + pkgbin_name(provider->up->up, &provider->up->up->available, + pnaw_nonambig), possi->ed->name); /* We can't remove the one we're about to install: */ if (canfixbyremove) *canfixbyremove = NULL; @@ -675,11 +686,11 @@ depisok(struct dependency *dep, struct varbuf *whynot, case PKG_STAT_INSTALLED: case PKG_STAT_TRIGGERSPENDING: case PKG_STAT_TRIGGERSAWAITED: - sprintf(linebuf, - _(" %.250s provides %.250s and is present and %s.\n"), - pkg_name(provider->up->up, pnaw_nonambig), possi->ed->name, - gettext(statusstrings[provider->up->up->status])); - varbuf_add_str(whynot, linebuf); + varbuf_add_fmt(whynot, _(" %.250s provides %.250s and " + "is present and %s.\n"), + pkg_name(provider->up->up, pnaw_nonambig), + possi->ed->name, + gettext(statusstrings[provider->up->up->status])); if (!canfixbyremove) return false; nconflicts++; -- Dpkg.Org's dpkg

