chiark / gitweb /
fileio: write_string_stream_ts: return errors from fputs and fputc
authorMike Gilbert <floppym@gentoo.org>
Thu, 28 Dec 2017 02:46:52 +0000 (21:46 -0500)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:46 +0000 (07:49 +0200)
Ignoring errors from these functions may mask errors returned by the
kernel.

Fixes: https://github.com/systemd/systemd/issues/7744
src/basic/fileio.c

index 5a918c1e7d6a0b340b3d4de5ae32796f1c75994c..eb92ac5955d634a49e4ec855855ca563f0dd5f87 100644 (file)
@@ -65,9 +65,12 @@ int write_string_stream_ts(
         assert(f);
         assert(line);
 
-        fputs(line, f);
+        if (fputs(line, f) == EOF)
+                return -errno;
+
         if (!(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n"))
-                fputc('\n', f);
+                if (fputc('\n', f) == EOF)
+                        return -errno;
 
         if (ts) {
                 struct timespec twice[2] = {*ts, *ts};