[njs] Checking the return value of fstat().

Dmitry Volyntsev xeioex at nginx.com
Fri Sep 1 15:51:52 UTC 2017


details:   http://hg.nginx.org/njs/rev/616370bb1386
branches:  
changeset: 408:616370bb1386
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Sep 01 18:51:20 2017 +0300
description:
Checking the return value of fstat().

Just to make sure and to make Coverity Scan happy.

diffstat:

 njs/njs.c |  9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r fa735c652e7c -r 616370bb1386 njs/njs.c
--- a/njs/njs.c	Fri Sep 01 18:51:20 2017 +0300
+++ b/njs/njs.c	Fri Sep 01 18:51:20 2017 +0300
@@ -323,7 +323,12 @@ njs_process_file(njs_opts_t *opts, njs_v
         }
     }
 
-    fstat(fd, &sb);
+    if (fstat(fd, &sb) == -1) {
+        fprintf(stderr, "fstat(%d) failed while reading '%s' (%s)\n",
+                fd, file, strerror(errno));
+        ret = NXT_ERROR;
+        goto close_fd;
+    }
 
     size = sizeof(buf);
 
@@ -407,6 +412,8 @@ done:
         free(script.start);
     }
 
+close_fd:
+
     if (fd != STDIN_FILENO) {
         close(fd);
     }


More information about the nginx-devel mailing list