[dpkg] 118/187: libdpkg: Return error in error_context_errmsg_format() only if truncated
Reiner Herrmann
reiner at reiner-h.de
Sun Nov 6 12:46:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
deki-guest pushed a commit to branch master
in repository dpkg.
commit d1f570622cff0fcfafd6b85f6beafce01d893563
Author: Guillem Jover <guillem at debian.org>
Date: Wed Aug 10 20:39:39 2016 +0200
libdpkg: Return error in error_context_errmsg_format() only if truncated
In case we have to use the emergency buffer because the previous
vasprintf() call failed, we should only return an error code if the
vsnprintf() call on the emergency buffer truncates the output.
---
debian/changelog | 4 ++++
lib/dpkg/ehandle.c | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index 3f20ad4..45f9b24 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -34,6 +34,10 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
Reported by Helmut Grohne <helmut at subdivi.de>.
* Only set the error context message in libdpkg if it has been formatted
correctly.
+ * Return error in error_context_errmsg_format() only if the error message
+ gets truncated. In case we have to use the emergency buffer because the
+ previous vasprintf() call failed, we should only return an error code if
+ the vsnprintf() call on the emergency buffer truncates the output.
* Architecture support:
- Add support for AIX operating system.
* Portability:
diff --git a/lib/dpkg/ehandle.c b/lib/dpkg/ehandle.c
index 517b073..53deb36 100644
--- a/lib/dpkg/ehandle.c
+++ b/lib/dpkg/ehandle.c
@@ -202,7 +202,11 @@ error_context_errmsg_format(const char *fmt, va_list args)
/* If there was any error, just use the emergency error message buffer,
* even if it ends up being truncated, at least we will have a big part
* of the problem. */
- vsnprintf(emergency.errmsg, sizeof(emergency.errmsg), fmt, args);
+ rc = vsnprintf(emergency.errmsg, sizeof(emergency.errmsg), fmt, args);
+
+ /* Return failure only if we get truncated. */
+ if (rc >= (int)sizeof(emergency.errmsg))
+ rc = -1;
error_context_errmsg_set(econtext, emergency.errmsg);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list