nfsdcld: Fix a number of Coverity Scan
Subsystems (2)
cover nfsdcld: Fix a number of Coverity Scan
These patches fix some errors in nfsdcld flagged by the Coverity scan software.
Scott Mayhew (5):
nfsdcld: Fix a few Coverity Scan RESOURCE_LEAK errors
nfsdcld: Fix a few Coverity Scan TOCTOU errors
nfsdcld: Fix a few Coverity Scan STRING_NULL errors
nfsdcld: Fix a few Coverity Scan CLANG_WARNING errors
nfsdcld: Fix a few Coverity Scan CHECKED_RETURN errors.
utils/nfsdcld/legacy.c | 38 ++++++++++++-------------------------- utils/nfsdcld/nfsdcld.c | 7 +++++-- utils/nfsdcld/sqlite.c | 5 +++-- 3 files changed, 20 insertions(+), 30 deletions(-)
Signature · 1 line
2.25.4
PATCH 1/5 nfsdcld: Fix a few Coverity Scan RESOURCE_LEAK errors
--- utils/nfsdcld/legacy.c | 2 ++ utils/nfsdcld/nfsdcld.c | 1 + utils/nfsdcld/sqlite.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-)
utils/nfsdcld/legacy.c +2 -0
@@ -60,6 +60,7 @@ legacy_load_clients_from_recdir(int *num_records) }if (read (fd, recdirname,PATH_MAX ) <0 ) {xlog (D_GENERAL ,"Unable to read from %s: %m" ,NFSD_RECDIR_FILE ); +close (fd);return ; }close (fd);
@@ -135,6 +136,7 @@ legacy_clear_recdir(void) }if (read (fd, recdirname,PATH_MAX ) <0 ) {xlog (D_GENERAL ,"Unable to read from %s: %m" ,NFSD_RECDIR_FILE ); +close (fd);return ; }close (fd);
utils/nfsdcld/nfsdcld.c +1 -0
@@ -331,6 +331,7 @@ cld_check_grace_period(void)if (read (fd, &c,1 ) <0 ) {xlog (L_WARNING ,"Unable to read from %s: %m" ,NFSD_END_GRACE_FILE ); +close (fd);return 1 ; }close (fd);
utils/nfsdcld/sqlite.c +1 -1
@@ -380,7 +380,7 @@ sqlite_maindb_init_v4(void) &err);if (ret !=SQLITE_OK ) {xlog (L_ERROR ,"Unable to begin transaction: %s" , err); -return ret; + goto out; }/*
Signature · 1 line
2.25.4
PATCH 2/5 nfsdcld: Fix a few Coverity Scan TOCTOU errors
In reply to Scott MayhewCalling stat() on recdirname so that we can see if it's a directory is unnecessary anyways, since opendir() will report an error if it's not.
--- utils/nfsdcld/legacy.c | 20 -------------------- 1 file changed, 20 deletions(-)
utils/nfsdcld/legacy.c +0 -20
@@ -50,7 +50,6 @@ legacy_load_clients_from_recdir(int *num_records)struct dirent *entry;char recdirname[PATH_MAX ];char buf[NFS4_OPAQUE_LIMIT ]; -struct stat st;char *nl; fd =open (NFSD_RECDIR_FILE ,O_RDONLY );
@@ -69,15 +68,6 @@ legacy_load_clients_from_recdir(int *num_records)if (!nl)return ; *nl ='\0' ; -if (stat (recdirname, &st) <0 ) { -xlog (D_GENERAL ,"Unable to stat %s: %d" , recdirname, errno); -return ; - } -if (!S_ISDIR (st.st_mode)) { -xlog (D_GENERAL ,"%s is not a directory: mode=0%o" , recdirname - , st.st_mode); -return ; - } v4recovery =opendir (recdirname);if (!v4recovery)return ;
@@ -126,7 +116,6 @@ legacy_clear_recdir(void)struct dirent *entry;char recdirname[PATH_MAX ];char dirname[PATH_MAX ]; -struct stat st;char *nl; fd =open (NFSD_RECDIR_FILE ,O_RDONLY );
@@ -145,15 +134,6 @@ legacy_clear_recdir(void)if (!nl)return ; *nl ='\0' ; -if (stat (recdirname, &st) <0 ) { -xlog (D_GENERAL ,"Unable to stat %s: %d" , recdirname, errno); -return ; - } -if (!S_ISDIR (st.st_mode)) { -xlog (D_GENERAL ,"%s is not a directory: mode=0%o" , recdirname - , st.st_mode); -return ; - } v4recovery =opendir (recdirname);if (!v4recovery)return ;
Signature · 1 line
2.25.4
PATCH 3/5 nfsdcld: Fix a few Coverity Scan STRING_NULL errors
In reply to Scott Mayhew--- utils/nfsdcld/legacy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
utils/nfsdcld/legacy.c +4 -2
@@ -48,7 +48,7 @@ legacy_load_clients_from_recdir(int *num_records)int fd;DIR *v4recovery;struct dirent *entry; -char recdirname[PATH_MAX ]; +char recdirname[PATH_MAX +1 ];char buf[NFS4_OPAQUE_LIMIT ];char *nl;
@@ -64,6 +64,7 @@ legacy_load_clients_from_recdir(int *num_records) }close (fd);/* the output from the proc file isn't null-terminated */ + recdirname[PATH_MAX ] ='\0' ; nl =strchr (recdirname,'\n' );if (!nl)return ;
@@ -114,7 +115,7 @@ legacy_clear_recdir(void)int fd;DIR *v4recovery;struct dirent *entry; -char recdirname[PATH_MAX ]; +char recdirname[PATH_MAX +1 ];char dirname[PATH_MAX ];char *nl;
@@ -130,6 +131,7 @@ legacy_clear_recdir(void) }close (fd);/* the output from the proc file isn't null-terminated */ + recdirname[PATH_MAX ] ='\0' ; nl =strchr (recdirname,'\n' );if (!nl)return ;
Signature · 1 line
2.25.4
PATCH 4/5 nfsdcld: Fix a few Coverity Scan CLANG_WARNING errors
In reply to Scott Mayhew--- utils/nfsdcld/nfsdcld.c | 6 ++++-- utils/nfsdcld/sqlite.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)
utils/nfsdcld/nfsdcld.c +4 -2
@@ -252,11 +252,12 @@ cld_inotify_setup(void)xlog_err ("%s: inotify_add_watch failed: %m" , __func__); ret = -errno; goto out_err; - } + }else + ret =0 ; out_free:free (dirc); -return 0 ; +return ret; out_err:close (inotify_fd); goto out_free;
@@ -796,6 +797,7 @@ main(int argc, char **argv)break ;default :usage (progname); +free (progname);return 0 ; } }
utils/nfsdcld/sqlite.c +2 -1
@@ -831,7 +831,6 @@ sqlite_prepare_dbh(const char *topdir)switch (ret) {case CLD_SQLITE_LATEST_SCHEMA_VERSION :/* DB is already set up. Do nothing */ - ret =0 ;break ;case 3 :/* Old DB -- update to new schema */
@@ -868,6 +867,8 @@ sqlite_prepare_dbh(const char *topdir) } ret =sqlite_startup_query_grace (); +if (ret) + goto out_close; ret =sqlite_query_first_time (&first_time);if (ret)
Signature · 1 line
2.25.4
PATCH 5/5 nfsdcld: Fix a few Coverity Scan CHECKED_RETURN errors.
In reply to Scott Mayhew--- utils/nfsdcld/legacy.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
utils/nfsdcld/legacy.c +8 -6
@@ -51,18 +51,19 @@ legacy_load_clients_from_recdir(int *num_records)char recdirname[PATH_MAX +1 ];char buf[NFS4_OPAQUE_LIMIT ];char *nl; +ssize_t n; fd =open (NFSD_RECDIR_FILE ,O_RDONLY );if (fd <0 ) {xlog (D_GENERAL ,"Unable to open %s: %m" ,NFSD_RECDIR_FILE );return ; } -if (read (fd, recdirname,PATH_MAX ) <0 ) { + n =read (fd, recdirname,PATH_MAX ); +close (fd); +if (n <0 ) {xlog (D_GENERAL ,"Unable to read from %s: %m" ,NFSD_RECDIR_FILE ); -close (fd);return ; } -close (fd);/* the output from the proc file isn't null-terminated */ recdirname[PATH_MAX ] ='\0' ; nl =strchr (recdirname,'\n' );
@@ -118,18 +119,19 @@ legacy_clear_recdir(void)char recdirname[PATH_MAX +1 ];char dirname[PATH_MAX ];char *nl; +ssize_t n; fd =open (NFSD_RECDIR_FILE ,O_RDONLY );if (fd <0 ) {xlog (D_GENERAL ,"Unable to open %s: %m" ,NFSD_RECDIR_FILE );return ; } -if (read (fd, recdirname,PATH_MAX ) <0 ) { + n =read (fd, recdirname,PATH_MAX ); +close (fd); +if (n <0 ) {xlog (D_GENERAL ,"Unable to read from %s: %m" ,NFSD_RECDIR_FILE ); -close (fd);return ; } -close (fd);/* the output from the proc file isn't null-terminated */ recdirname[PATH_MAX ] ='\0' ; nl =strchr (recdirname,'\n' );
Signature · 1 line
2.25.4
Quoted 10 lines · Scott Mayhew
These patches fix some errors in nfsdcld flagged by the Coverity scan software.
Scott Mayhew (5):
nfsdcld: Fix a few Coverity ScanRESOURCE_LEAKerrors
nfsdcld: Fix a few Coverity Scan TOCTOU errors
nfsdcld: Fix a few Coverity ScanSTRING_NULLerrors
nfsdcld: Fix a few Coverity ScanCLANG_WARNINGerrors
nfsdcld: Fix a few Coverity ScanCHECKED_RETURNerrors.
Quoted 5 lines
utils/nfsdcld/legacy.c | 38 ++++++++++++-------------------------- utils/nfsdcld/nfsdcld.c | 7 +++++-- utils/nfsdcld/sqlite.c | 5 +++-- 3 files changed, 20 insertions(+), 30 deletions(-)
Committed... (tag: nfs-utils-2-5-2-rc2)
steved.