diff mbox series

[06/11] libselinux: fail selabel_open(3) on invalid option

Message ID 20231219160943.334370-6-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 65c8fd457b05
Delegated to: Petr Lautrbach
Headers show
Series [01/11] libselinux/man: mention errno for regex compilation failure | expand

Commit Message

Christian Göttsche Dec. 19, 2023, 4:09 p.m. UTC
Return an error on invalid selabel_open(3) options, e.g. an option for
a different backend was used.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/label_backends_android.c | 7 +++++++
 libselinux/src/label_db.c               | 8 ++++++++
 libselinux/src/label_file.c             | 7 +++++++
 libselinux/src/label_media.c            | 7 +++++++
 libselinux/src/label_x.c                | 7 +++++++
 5 files changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/libselinux/src/label_backends_android.c b/libselinux/src/label_backends_android.c
index cd3875fc..7ddacdbe 100644
--- a/libselinux/src/label_backends_android.c
+++ b/libselinux/src/label_backends_android.c
@@ -157,6 +157,13 @@  static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 		case SELABEL_OPT_PATH:
 			path = opts[n].value;
 			break;
+		case SELABEL_OPT_UNUSED:
+		case SELABEL_OPT_VALIDATE:
+		case SELABEL_OPT_DIGEST:
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
 		}
 
 	if (!path)
diff --git a/libselinux/src/label_db.c b/libselinux/src/label_db.c
index 3f803037..2daf1770 100644
--- a/libselinux/src/label_db.c
+++ b/libselinux/src/label_db.c
@@ -268,6 +268,14 @@  db_init(const struct selinux_opt *opts, unsigned nopts,
 		case SELABEL_OPT_PATH:
 			path = opts[nopts].value;
 			break;
+		case SELABEL_OPT_UNUSED:
+		case SELABEL_OPT_VALIDATE:
+		case SELABEL_OPT_DIGEST:
+			break;
+		default:
+			free(catalog);
+			errno = EINVAL;
+			return NULL;
 		}
 	}
 
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 4778f8f8..315298b3 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -812,6 +812,13 @@  static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 		case SELABEL_OPT_BASEONLY:
 			baseonly = !!opts[n].value;
 			break;
+		case SELABEL_OPT_UNUSED:
+		case SELABEL_OPT_VALIDATE:
+		case SELABEL_OPT_DIGEST:
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
 		}
 
 #if !defined(BUILD_HOST) && !defined(ANDROID)
diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c
index b3443b47..4c987988 100644
--- a/libselinux/src/label_media.c
+++ b/libselinux/src/label_media.c
@@ -85,6 +85,13 @@  static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 		case SELABEL_OPT_PATH:
 			path = opts[n].value;
 			break;
+		case SELABEL_OPT_UNUSED:
+		case SELABEL_OPT_VALIDATE:
+		case SELABEL_OPT_DIGEST:
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
 		}
 
 	/* Open the specification file. */
diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c
index e15190ca..f332dcb6 100644
--- a/libselinux/src/label_x.c
+++ b/libselinux/src/label_x.c
@@ -112,6 +112,13 @@  static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 		case SELABEL_OPT_PATH:
 			path = opts[n].value;
 			break;
+		case SELABEL_OPT_UNUSED:
+		case SELABEL_OPT_VALIDATE:
+		case SELABEL_OPT_DIGEST:
+			break;
+		default:
+			errno = EINVAL;
+			return -1;
 		}
 
 	/* Open the specification file. */