diff options
| author | Walter Lozano <walter.lozano@collabora.com> | 2022-10-14 09:13:00 -0300 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-05-19 15:58:13 +0000 |
| commit | 91e8c456964d5ff4b3b7afe2f1cb074de9dfe592 (patch) | |
| tree | 00878cbd2e3e9cfa290a366550159f0a7b255ce0 /apt-pkg | |
| parent | d0ecc3286b4487d3b3f2809c95233863bffdada5 (diff) | |
Fix error handling with getline
The function getline is used to read data from different streams, however,
the error handling is not accurate.
From the man page, getline returns -1 on failure and sets errno accordingly,
but the current implementation only checks errno to see if there was a
failure. With this approach, in case getline returns success but also sets
errno it is consider and error.
Fix the issue but also checking the return value of getline.
Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/contrib/fileutl.cc | 2 | ||||
| -rw-r--r-- | apt-pkg/contrib/gpgv.cc | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 4dd7b1ac3..85997275c 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1003,7 +1003,7 @@ bool StartsWithGPGClearTextSignature(string const &FileName) errno = 0; DEFER([&] { fclose(gpg); free(lineptr); }); ssize_t const result = getline(&lineptr, &n, gpg); - if (errno != 0) + if (result < 0 && errno != 0) { _error->Errno("getline", "Could not read from %s", FileName.c_str()); return false; diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index b555331d6..0341521ac 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -76,7 +76,7 @@ class LineBuffer /*{{{*/ { errno = 0; line_length = getline(&buffer, &buffer_size, stream); - if (errno != 0) + if (line_length < 0 && errno != 0) return _error->Errno("getline", "Could not read from %s", InFile.c_str()); if (line_length == -1) { |
