aboutsummaryrefslogtreecommitdiff
path: root/doc/nx-X11_vs_XOrg69_patches/AuRead.c.NX.patch
blob: 940a3fee40ff891f85e508473f35bf5da2491e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--- ./nx-X11/lib/Xau/AuRead.c.X.original	2015-02-13 14:03:44.624443872 +0100
+++ ./nx-X11/lib/Xau/AuRead.c	2015-02-10 19:13:12.488735202 +0100
@@ -32,14 +32,29 @@
 #endif
 #include <X11/Xauth.h>
 #include <stdlib.h>
+#include <errno.h>
 
 static int
 read_short (unsigned short *shortp, FILE *file)
 {
     unsigned char   file_short[2];
 
-    if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
-	return 0;
+    /*
+     * Added a check on EINTR to prevent the fread() call to be
+     * interrupted by any signal not blocked by OsBlockSignals().
+     */
+
+    for (;;) {
+        if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) {
+            if (errno == EINTR && ferror (file)) {
+                perror ("Reading from auth file");
+                clearerr (file);
+                continue;
+            }
+            return 0;
+        }
+        break;
+    }
     *shortp = file_short[0] * 256 + file_short[1];
     return 1;
 }
@@ -58,11 +73,22 @@
     	data = malloc ((unsigned) len);
     	if (!data)
 	    return 0;
-    	if (fread (data, (int) sizeof (char), (int) len, file) != len) {
-	    bzero (data, len);
-	    free (data);
-	    return 0;
-    	}
+        for (;;)
+        {
+            if (fread (data, (int) sizeof (char), (int) len, file) != len)
+            {
+                if (errno == EINTR && ferror (file))
+                {
+                    perror ("Reading from auth file");
+                    clearerr (file);
+                    continue;
+                }
+	        bzero (data, len);
+	        free (data);
+	        return 0;
+    	    }
+            break;
+        }
     }
     *stringp = data;
     *countp = len;