xserver: Branch 'master' - 8 commits

Keith Packard keithp at kemper.freedesktop.org
Fri Apr 18 16:31:16 PDT 2014


 hw/kdrive/linux/linux.c |    7 +++++--
 hw/kdrive/src/kdrive.c  |    9 ++++++++-
 os/connection.c         |    7 +++++--
 os/log.c                |   10 ++++++++--
 os/utils.c              |    3 ++-
 test/signal-logging.c   |   11 ++++++++---
 xkb/xkmread.c           |    6 ++++--
 7 files changed, 40 insertions(+), 13 deletions(-)

New commits:
commit c7011249d2abe6cc7af82ee4b79d8f6873444707
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 15:12:14 2014 -0700

    xkb: Verify reads of compiled keymap header and TOC
    
    Check the return values from fread to make sure the elements are
    actually getting read from the file.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/xkb/xkmread.c b/xkb/xkmread.c
index 258bb91..b6241b5 100644
--- a/xkb/xkmread.c
+++ b/xkb/xkmread.c
@@ -1204,7 +1204,8 @@ XkmReadTOC(FILE * file, xkmFileInfo * file_info, int max_toc,
         }
         return 0;
     }
-    fread(file_info, SIZEOF(xkmFileInfo), 1, file);
+    if (fread(file_info, SIZEOF(xkmFileInfo), 1, file) != 1)
+        return 0;
     size_toc = file_info->num_toc;
     if (size_toc > max_toc) {
         DebugF("Warning! Too many TOC entries; last %d ignored\n",
@@ -1212,7 +1213,8 @@ XkmReadTOC(FILE * file, xkmFileInfo * file_info, int max_toc,
         size_toc = max_toc;
     }
     for (i = 0; i < size_toc; i++) {
-        fread(&toc[i], SIZEOF(xkmSectionInfo), 1, file);
+        if (fread(&toc[i], SIZEOF(xkmSectionInfo), 1, file) != 1)
+            return 0;
     }
     return 1;
 }
commit 0af8788579c2f52cc1172952c9004483bf863932
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 15:09:50 2014 -0700

    os: Ignore log file write failures
    
    There's no place to log the message if writing to the log file fails,
    and we surely don't want to crash in that case, so just ignore errors
    and keep going.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/os/log.c b/os/log.c
index 38193ee..a0f2a81 100644
--- a/os/log.c
+++ b/os/log.c
@@ -491,13 +491,14 @@ static void
 LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
 {
     static Bool newline = TRUE;
+    int ret;
 
     if (verb < 0 || logVerbosity >= verb)
-        write(2, buf, len);
+        ret = write(2, buf, len);
 
     if (verb < 0 || logFileVerbosity >= verb) {
         if (inSignalContext && logFileFd >= 0) {
-            write(logFileFd, buf, len);
+            ret = write(logFileFd, buf, len);
 #ifndef WIN32
             if (logFlush && logSync)
                 fsync(logFileFd);
@@ -529,6 +530,11 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
             bufferPos += len;
         }
     }
+
+    /* There's no place to log an error message if the log write
+     * fails...
+     */
+    (void) ret;
 }
 
 void
commit 7abd28685066369ded807f59493c1159cfb286bf
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 15:05:00 2014 -0700

    os: Make sure that writing our pid to the lock file actually worked
    
    There's no sense verifying that we can create the lock file and then
    ignoring the return value from write.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/os/utils.c b/os/utils.c
index 6e6974e..83d85cd 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -313,7 +313,8 @@ LockServer(void)
     if (lfd < 0)
         FatalError("Could not create lock file in %s\n", tmp);
     snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
-    (void) write(lfd, pid_str, 11);
+    if (write(lfd, pid_str, 11) != 11)
+        FatalError("Could not write pid to lock file in %s\n", tmp);
     (void) fchmod(lfd, 0444);
     (void) close(lfd);
 
commit d72f691c0c9cace857975a6608a4cb431c8b6846
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 15:00:30 2014 -0700

    os: FatalError if -displayfd writes fail
    
    When the server is started with the -displayfd option, check to make
    sure that the writes succeed and give up running if they don't.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/os/connection.c b/os/connection.c
index 5294e59..40d9ff3 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -353,8 +353,10 @@ NotifyParentProcess(void)
 {
 #if !defined(WIN32)
     if (displayfd >= 0) {
-        write(displayfd, display, strlen(display));
-        write(displayfd, "\n", 1);
+        if (write(displayfd, display, strlen(display)) != strlen(display))
+            FatalError("Cannot write display number to fd %d\n", displayfd);
+        if (write(displayfd, "\n", 1) != 1)
+            FatalError("Cannot write display number to fd %d\n", displayfd);
         close(displayfd);
         displayfd = -1;
     }
commit 4957e986841225e9984daca76f1a0ee08df125bb
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 15:00:35 2014 -0700

    os: Clear the -displayfd option after closing the file
    
    Failing to clear this means that we'll attempt to write the display
    number to a random file descriptor on subsequent X server generations.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/os/connection.c b/os/connection.c
index e914d9d..5294e59 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -356,6 +356,7 @@ NotifyParentProcess(void)
         write(displayfd, display, strlen(display));
         write(displayfd, "\n", 1);
         close(displayfd);
+        displayfd = -1;
     }
     if (RunFromSmartParent) {
         if (ParentProcess > 1) {
commit 0c0feddbcda238efa82a47f456ef3008ffa53195
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 14:54:02 2014 -0700

    kdrive: Ignore failure to chown console tty to current user
    
    I'm not sure what we'd do in this case anyways, other than fatal
    error.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index 6284de5..73a8169 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -68,13 +68,16 @@ LinuxCheckChown(const char *file)
     struct stat st;
     __uid_t u;
     __gid_t g;
+    int r;
 
     if (stat(file, &st) < 0)
         return;
     u = getuid();
     g = getgid();
-    if (st.st_uid != u || st.st_gid != g)
-        chown(file, u, g);
+    if (st.st_uid != u || st.st_gid != g) {
+        r = chown(file, u, g);
+        (void) r;
+    }
 }
 
 static int
commit 696e08f8e820449bb4b0ce7a60bf5b5bc5097935
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 14:50:14 2014 -0700

    kdrive: Explicitly ignore errors from the -switchCmd script
    
    Make it clear that we intentionally ignore the -switchCmd return
    value. This keeps GCC from emitting a warning when the server is
    compiled with -D_FORTIFY_SOURCE=2.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 8eb8cd0..9814fc6 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -118,10 +118,17 @@ KdDoSwitchCmd(const char *reason)
 {
     if (kdSwitchCmd) {
         char *command;
+        int ret;
 
         if (asprintf(&command, "%s %s", kdSwitchCmd, reason) == -1)
             return;
-        system(command);
+
+        /* Ignore the return value from system; I'm not sure
+         * there's anything more useful to be done when
+         * it fails
+         */
+        ret = system(command);
+        (void) ret;
         free(command);
     }
 }
commit 570b1c79942b237022be3594ae3a25e7b833cb73
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 18 14:47:00 2014 -0700

    test: [v2] Validate server log reading more carefully in signal-logging test
    
    Check return value from fgets and strchr instead of assuming they
    worked.
    
    [v2]
    
    Don't do any necessary work inside the assert call.
    Also make sure the return value was long enough.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/test/signal-logging.c b/test/signal-logging.c
index 88b37c1..4320121 100644
--- a/test/signal-logging.c
+++ b/test/signal-logging.c
@@ -178,9 +178,14 @@ static void logging_format(void)
     LogInit(log_file_path, NULL);
     assert(f = fopen(log_file_path, "r"));
 
-#define read_log_msg(msg) \
-    fgets(read_buf, sizeof(read_buf), f); \
-    msg = strchr(read_buf, ']') + 2; /* advance past [time.stamp] */
+#define read_log_msg(msg) do {                                  \
+        msg = fgets(read_buf, sizeof(read_buf), f);             \
+        assert(msg != NULL);                                   \
+        msg = strchr(read_buf, ']');                            \
+        assert(msg != NULL);                                    \
+        assert(strlen(msg) > 2);                                \
+        msg = msg + 2; /* advance past [time.stamp] */          \
+    } while (0)
 
     /* boring test message */
     LogMessageVerbSigSafe(X_ERROR, -1, "test message\n");


More information about the xorg-commit mailing list