Workarounds for compiling with -D_FORTIFY_SOURCE=2 (as Ubuntu does), which
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Fri, 7 Aug 2009 00:19:04 +0000 (00:19 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Fri, 7 Aug 2009 00:19:04 +0000 (00:19 +0000)
doesn't like you to ignore the return value from read()/write()/etc (and
apparently can't be shut up with a cast to void).

git-svn-id: svn://svn.tartarus.org/sgt/putty@8614 cda61777-01e9-0310-a592-d414129be87e

logging.c
pscp.c
psftp.c
unix/uxcons.c
unix/uxplink.c
unix/uxpty.c

index f1e3729..49269ec 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -43,7 +43,10 @@ static void logwrite(struct LogContext *ctx, void *data, int len)
        bufchain_add(&ctx->queue, data, len);
     } else if (ctx->state == L_OPEN) {
        assert(ctx->lgfp);
-       fwrite(data, 1, len, ctx->lgfp);
+       if (fwrite(data, 1, len, ctx->lgfp) < len) {
+           logfclose(ctx);
+           ctx->state = L_ERROR;
+       }
     }                                 /* else L_ERROR, so ignore the write */
 }
 
diff --git a/pscp.c b/pscp.c
index ab3077b..451bdb0 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -178,7 +178,8 @@ int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
      */
     if (is_stderr) {
        if (len > 0)
-           fwrite(data, 1, len, stderr);
+           if (fwrite(data, 1, len, stderr) < len)
+               /* oh well */;
        return 0;
     }
 
diff --git a/psftp.c b/psftp.c
index e0fbee8..65d52c3 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -2518,7 +2518,8 @@ int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
      */
     if (is_stderr) {
        if (len > 0)
-           fwrite(data, 1, len, stderr);
+           if (fwrite(data, 1, len, stderr) < len)
+               /* oh well */;
        return 0;
     }
 
index 2021f40..11c59a8 100644 (file)
@@ -161,7 +161,8 @@ int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
        newmode.c_lflag |= ECHO | ISIG | ICANON;
        tcsetattr(0, TCSANOW, &newmode);
        line[0] = '\0';
-       read(0, line, sizeof(line) - 1);
+       if (read(0, line, sizeof(line) - 1) <= 0)
+           /* handled below */;
        tcsetattr(0, TCSANOW, &oldmode);
     }
 
@@ -213,7 +214,8 @@ int askalg(void *frontend, const char *algtype, const char *algname,
        newmode.c_lflag |= ECHO | ISIG | ICANON;
        tcsetattr(0, TCSANOW, &newmode);
        line[0] = '\0';
-       read(0, line, sizeof(line) - 1);
+       if (read(0, line, sizeof(line) - 1) <= 0)
+           /* handled below */;
        tcsetattr(0, TCSANOW, &oldmode);
     }
 
@@ -266,7 +268,8 @@ int askappend(void *frontend, Filename filename,
        newmode.c_lflag |= ECHO | ISIG | ICANON;
        tcsetattr(0, TCSANOW, &newmode);
        line[0] = '\0';
-       read(0, line, sizeof(line) - 1);
+       if (read(0, line, sizeof(line) - 1) <= 0)
+           /* handled below */;
        tcsetattr(0, TCSANOW, &oldmode);
     }
 
index 6d9a9b7..cbfcc71 100644 (file)
@@ -513,7 +513,8 @@ int signalpipe[2];
 
 void sigwinch(int signum)
 {
-    write(signalpipe[1], "x", 1);
+    if (write(signalpipe[1], "x", 1) <= 0)
+       /* not much we can do about it */;
 }
 
 /*
@@ -1030,7 +1031,9 @@ int main(int argc, char **argv)
        if (FD_ISSET(signalpipe[0], &rset)) {
            char c[1];
            struct winsize size;
-           read(signalpipe[0], c, 1); /* ignore its value; it'll be `x' */
+           if (read(signalpipe[0], c, 1) <= 0)
+               /* ignore error */;
+           /* ignore its value; it'll be `x' */
            if (ioctl(0, TIOCGWINSZ, (void *)&size) >= 0)
                back->size(backhandle, size.ws_col, size.ws_row);
        }
index ca7e98a..5de43a3 100644 (file)
@@ -260,7 +260,8 @@ static void cleanup_utmp(void)
 
 static void sigchld_handler(int signum)
 {
-    write(pty_signal_pipe[1], "x", 1);
+    if (write(pty_signal_pipe[1], "x", 1) <= 0)
+       /* not much we can do about it */;
 }
 
 #ifndef OMIT_UTMP
@@ -633,7 +634,9 @@ int pty_select_result(int fd, int event)
        int status;
        char c[1];
 
-       read(pty_signal_pipe[0], c, 1); /* ignore its value; it'll be `x' */
+       if (read(pty_signal_pipe[0], c, 1) <= 0)
+           /* ignore error */;
+       /* ignore its value; it'll be `x' */
 
        do {
            pid = waitpid(-1, &status, WNOHANG);