* [PATCH] secilc: better error handling
@ 2018-09-22 0:08 Nick Kralevich
2018-09-22 0:17 ` William Roberts
0 siblings, 1 reply; 2+ messages in thread
From: Nick Kralevich @ 2018-09-22 0:08 UTC (permalink / raw)
To: selinux
Fix a situation where the secilc command line tool could return success
even though the compilation failed.
$ secilc /dev/null -o /dev/null -f /dev/null
Failure reading file: /dev/null
$ echo $?
0
Fix a few other minor oversights while I'm here.
Signed-off-by: Nick Kralevich <nnk@google.com>
---
libsepol/include/sepol/errcodes.h | 2 +-
secilc/secilc.c | 8 ++++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/libsepol/include/sepol/errcodes.h b/libsepol/include/sepol/e=
rrcodes.h
index 0136564a..6e9ff316 100644
--- a/libsepol/include/sepol/errcodes.h
+++ b/libsepol/include/sepol/errcodes.h
@@ -12,7 +12,7 @@ extern "C" {
#define SEPOL_OK 0
=20
/* These first error codes are defined for compatibility with
- * previous version of libsepol. In the future, custome error
+ * previous version of libsepol. In the future, custom error
* codes that don't map to system error codes should be defined
* outside of the range of system error codes.
*/
diff --git a/secilc/secilc.c b/secilc/secilc.c
index 0be6975b..8578cc26 100644
--- a/secilc/secilc.c
+++ b/secilc/secilc.c
@@ -257,14 +257,16 @@ int main(int argc, char *argv[])
rc =3D stat(argv[i], &filedata);
if (rc =3D=3D -1) {
fprintf(stderr, "Could not stat file: %s\n", argv[i]);
+ rc =3D SEPOL_ERR;
goto exit;
}
- file_size =3D filedata.st_size;=09
+ file_size =3D filedata.st_size;
=20
buffer =3D malloc(file_size);
rc =3D fread(buffer, file_size, 1, file);
if (rc !=3D 1) {
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
+ rc =3D SEPOL_ERR;
goto exit;
}
fclose(file);
@@ -345,11 +347,13 @@ int main(int argc, char *argv[])
=20
if (file_contexts =3D=3D NULL) {
fprintf(stderr, "Failed to open file_contexts file\n");
+ rc =3D SEPOL_ERR;
goto exit;
}
-=09
+
if (fwrite(fc_buf, sizeof(char), fc_size, file_contexts) !=3D fc_size) =
{
fprintf(stderr, "Failed to write file_contexts file\n");
+ rc =3D SEPOL_ERR;
goto exit;
}
=20
--=20
2.19.0.444.g18242da7ef-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] secilc: better error handling
2018-09-22 0:08 [PATCH] secilc: better error handling Nick Kralevich
@ 2018-09-22 0:17 ` William Roberts
0 siblings, 0 replies; 2+ messages in thread
From: William Roberts @ 2018-09-22 0:17 UTC (permalink / raw)
To: Nick Kralevich; +Cc: selinux
[-- Attachment #1: Type: text/plain, Size: 3010 bytes --]
On Fri, Sep 21, 2018 at 5:12 PM Nick Kralevich via Selinux <
selinux@tycho.nsa.gov> wrote:
> Fix a situation where the secilc command line tool could return success
> even though the compilation failed.
>
> $ secilc /dev/null -o /dev/null -f /dev/null
> Failure reading file: /dev/null
> $ echo $?
> 0
>
> Fix a few other minor oversights while I'm here.
>
I'd prefer this split into at least 2 patches on the off chance we
need to revert the actual code changes we don't lose the spelling
and whitespace fixes. Otherwise LGTM.
>
> Signed-off-by: Nick Kralevich <nnk@google.com>
> ---
> libsepol/include/sepol/errcodes.h | 2 +-
> secilc/secilc.c | 8 ++++++--
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libsepol/include/sepol/errcodes.h
> b/libsepol/include/sepol/errcodes.h
> index 0136564a..6e9ff316 100644
> --- a/libsepol/include/sepol/errcodes.h
> +++ b/libsepol/include/sepol/errcodes.h
> @@ -12,7 +12,7 @@ extern "C" {
> #define SEPOL_OK 0
>
> /* These first error codes are defined for compatibility with
> - * previous version of libsepol. In the future, custome error
> + * previous version of libsepol. In the future, custom error
> * codes that don't map to system error codes should be defined
> * outside of the range of system error codes.
> */
> diff --git a/secilc/secilc.c b/secilc/secilc.c
> index 0be6975b..8578cc26 100644
> --- a/secilc/secilc.c
> +++ b/secilc/secilc.c
> @@ -257,14 +257,16 @@ int main(int argc, char *argv[])
> rc = stat(argv[i], &filedata);
> if (rc == -1) {
> fprintf(stderr, "Could not stat file: %s\n",
> argv[i]);
> + rc = SEPOL_ERR;
> goto exit;
> }
> - file_size = filedata.st_size;
> + file_size = filedata.st_size;
>
> buffer = malloc(file_size);
> rc = fread(buffer, file_size, 1, file);
> if (rc != 1) {
> fprintf(stderr, "Failure reading file: %s\n",
> argv[i]);
> + rc = SEPOL_ERR;
> goto exit;
> }
> fclose(file);
> @@ -345,11 +347,13 @@ int main(int argc, char *argv[])
>
> if (file_contexts == NULL) {
> fprintf(stderr, "Failed to open file_contexts file\n");
> + rc = SEPOL_ERR;
> goto exit;
> }
> -
> +
> if (fwrite(fc_buf, sizeof(char), fc_size, file_contexts) !=
> fc_size) {
> fprintf(stderr, "Failed to write file_contexts file\n");
> + rc = SEPOL_ERR;
> goto exit;
> }
>
> --
> 2.19.0.444.g18242da7ef-goog
>
> _______________________________________________
> Selinux mailing list
> Selinux@tycho.nsa.gov
> To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
> To get help, send an email containing "help" to
> Selinux-request@tycho.nsa.gov.
>
[-- Attachment #2: Type: text/html, Size: 4236 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-09-22 0:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-22 0:08 [PATCH] secilc: better error handling Nick Kralevich
2018-09-22 0:17 ` William Roberts
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.