secilc: Use fstat instead of stat to avoid TOCTOU issues
PATCH 1/1 secilc: Use fstat instead of stat to avoid TOCTOU issues
For secilc, secilcheck, secil2tree, and secil2conf use fstat instead of stat to avoid TOCTOU issues.
Signed-off-by James Carter <[email protected]>
--- secilc/secil2conf.c | 2 +- secilc/secil2tree.c | 2 +- secilc/secilc.c | 2 +- secilc/secilcheck.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
secilc/secil2conf.c +1 -1
@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); goto exit;
secilc/secil2tree.c +1 -1
@@ -155,7 +155,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); goto exit;
secilc/secilc.c +1 -1
@@ -282,7 +282,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); rc =SEPOL_ERR ;
secilc/secilcheck.c +1 -1
@@ -148,7 +148,7 @@ static int add_cil_file(const char *filename, struct cil_db *cdb)fprintf (stderr,"Could not open file: %s\n" , filename); goto exit; } -if (stat (filename, &filedata) <0 ) { +if (fstat (fileno (file), &filedata) <0 ) {fprintf (stderr,"Could not stat file: %s\n" , filename); goto exit; }
Signature · 1 line
2.54.0
Quoted 5 lines · James Carter
For secilc, secilcheck, secil2tree, and secil2conf use fstat instead of stat to avoid TOCTOU issues.
Signed-off-by James Carter <[email protected]>
Acked-by Stephen Smalley <[email protected]>
Quoted 62 lines
--- secilc/secil2conf.c | 2 +- secilc/secil2tree.c | 2 +- secilc/secilc.c | 2 +- secilc/secilcheck.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)secilc/secil2conf.c +1
-1@@ -147,7 +147,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); goto exit;secilc/secil2tree.c +1
-1@@ -155,7 +155,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); goto exit;secilc/secilc.c +1
-1@@ -282,7 +282,7 @@ int main(int argc, char *argv[]) rc =SEPOL_ERR ; goto exit; } - rc =stat (argv[i], &filedata); + rc =fstat (fileno (file), &filedata);if (rc ==-1 ) {fprintf (stderr,"Could not stat file: %s\n" , argv[i]); rc =SEPOL_ERR ;secilc/secilcheck.c +1
-2@@ -148,7 +148,7 @@ static int add_cil_file(const char *filename, struct cil_db *cdb)fprintf (stderr,"Could not open file: %s\n" , filename); goto exit; } -if (stat (filename, &filedata) <0 ) { +if (fstat (fileno (file), &filedata) <0 ) {fprintf (stderr,"Could not stat file: %s\n" , filename); goto exit; } --2.54.0
Stephen Smalley
maintainerQuoted 9 lines · Stephen Smalley
Quoted 5 lines · James Carter
For secilc, secilcheck, secil2tree, and secil2conf use fstat instead of stat to avoid TOCTOU issues.
Signed-off-by James Carter <[email protected]>Acked-by Stephen Smalley <[email protected]>
Merged.