Blame SOURCES/patch-2.7.6-check-of-return-value-of-fwrite.patch

796689
commit 1e9104c18019e7dc6b5590aea4b1d4f9d8ecfd56
796689
Author: Bruno Haible <bruno@clisp.org>
796689
Date:   Sat Apr 7 12:21:04 2018 +0200
796689
796689
    Fix check of return value of fwrite().
796689
    
796689
    * src/patch.c (copy_till): Consider incomplete fwrite() write as an error.
796689
    * src/pch.c (pch_write_line, do_ed_script): Likewise.
796689
796689
diff --git a/src/patch.c b/src/patch.c
796689
index 1ae91d9..3fcaec5 100644
796689
--- a/src/patch.c
796689
+++ b/src/patch.c
796689
@@ -2,7 +2,7 @@
796689
 
796689
 /* Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall
796689
 
796689
-   Copyright (C) 1989-1993, 1997-1999, 2002-2003, 2006, 2009-2012 Free Software
796689
+   Copyright (C) 1989-1993, 1997-1999, 2002-2003, 2006, 2009-2018 Free Software
796689
    Foundation, Inc.
796689
 
796689
    This program is free software: you can redistribute it and/or modify
796689
@@ -1641,7 +1641,7 @@ copy_till (struct outstate *outstate, lin lastline)
796689
 	if (size)
796689
 	  {
796689
 	    if ((! outstate->after_newline  &&  putc ('\n', fp) == EOF)
796689
-		|| ! fwrite (s, sizeof *s, size, fp))
796689
+		|| fwrite (s, sizeof *s, size, fp) < size)
796689
 	      write_fatal ();
796689
 	    outstate->after_newline = s[size - 1] == '\n';
796689
 	    outstate->zero_output = false;
796689
diff --git a/src/pch.c b/src/pch.c
796689
index cda3dfa..79a3c99 100644
796689
--- a/src/pch.c
796689
+++ b/src/pch.c
796689
@@ -2279,8 +2279,11 @@ pfetch (lin line)
796689
 bool
796689
 pch_write_line (lin line, FILE *file)
796689
 {
796689
-  bool after_newline = (p_len[line] > 0) && (p_line[line][p_len[line] - 1] == '\n');
796689
-  if (! fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file))
796689
+  bool after_newline =
796689
+    (p_len[line] > 0) && (p_line[line][p_len[line] - 1] == '\n');
796689
+
796689
+  if (fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file)
796689
+      < p_len[line])
796689
     write_fatal ();
796689
   return after_newline;
796689
 }
796689
@@ -2427,13 +2430,14 @@ do_ed_script (char const *inname, char const *outname,
796689
 	ed_command_letter = get_ed_command_letter (buf);
796689
 	if (ed_command_letter) {
796689
 	    if (tmpfp)
796689
-		if (! fwrite (buf, sizeof *buf, chars_read, tmpfp))
796689
+		if (fwrite (buf, sizeof *buf, chars_read, tmpfp) < chars_read)
796689
 		    write_fatal ();
796689
 	    if (ed_command_letter != 'd' && ed_command_letter != 's') {
796689
 	        p_pass_comments_through = true;
796689
 		while ((chars_read = get_line ()) != 0) {
796689
 		    if (tmpfp)
796689
-			if (! fwrite (buf, sizeof *buf, chars_read, tmpfp))
796689
+			if (fwrite (buf, sizeof *buf, chars_read, tmpfp)
796689
+			    < chars_read)
796689
 			    write_fatal ();
796689
 		    if (chars_read == 2  &&  strEQ (buf, ".\n"))
796689
 			break;
796689
@@ -2448,7 +2452,7 @@ do_ed_script (char const *inname, char const *outname,
796689
     }
796689
     if (dry_run || skip_rest_of_patch)
796689
       return;
796689
-    if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, tmpfp) == 0
796689
+    if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, tmpfp) < (size_t) 4
796689
 	|| fflush (tmpfp) != 0)
796689
       write_fatal ();
796689