"pacman -Q --changelog": fix writing uninit'd mem
Previously, when printing a package changelog to stdout, we would write chunks of data that were not necessarily nul-terminated to stdout using a function (fputs) which requires the input string to be nul-terminated. On my system, this would result in occasional garbage characters showing up in the "pacman -Qc" output. Fix this by never nul-terminating the chunk, and using the fwrite() function which takes an explicit input size and does not require a nul-terminated string. Signed-off-by: Carlo Teubner <carlo@cteubner.net>
This commit is contained in:
parent
fc503df449
commit
b0962ce900
1 changed files with 1 additions and 5 deletions
|
@ -466,11 +466,7 @@ void dump_pkg_changelog(alpm_pkg_t *pkg)
|
||||||
char buf[CLBUF_SIZE];
|
char buf[CLBUF_SIZE];
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) {
|
while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) {
|
||||||
if(ret < CLBUF_SIZE) {
|
fwrite(buf, 1, ret, stdout);
|
||||||
/* if we hit the end of the file, we need to add a null terminator */
|
|
||||||
*(buf + ret) = '\0';
|
|
||||||
}
|
|
||||||
fputs(buf, stdout);
|
|
||||||
}
|
}
|
||||||
alpm_pkg_changelog_close(pkg, fp);
|
alpm_pkg_changelog_close(pkg, fp);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
Loading…
Add table
Reference in a new issue