aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/label_support.c
diff options
context:
space:
mode:
authorWilliam Roberts <william.c.roberts@intel.com>2016-02-09 13:59:46 -0800
committerStephen Smalley <sds@tycho.nsa.gov>2016-02-17 09:10:41 -0500
commit2981e0ba3a869d12ed6f376581277847421db2e7 (patch)
tree7d27c22d34a0f2d67dc1a9fc0260a5b661213ce5 /libselinux/src/label_support.c
parent9d76b62fa744cfdd1cf48d83ade2401f2f889abd (diff)
downloadandroid_external_selinux-2981e0ba3a869d12ed6f376581277847421db2e7.tar.gz
android_external_selinux-2981e0ba3a869d12ed6f376581277847421db2e7.tar.bz2
android_external_selinux-2981e0ba3a869d12ed6f376581277847421db2e7.zip
read_spec_entry: fail on non-ascii
Inserting non-ascii characters into the following files: * file_contexts * property_contexts * service_contexts can cause a failure on labeling but still result in a successful build. Hard error on non-ascii characters with: <path>: line 229 error due to: Non-ASCII characters found Signed-off-by: William Roberts <william.c.roberts@intel.com>
Diffstat (limited to 'libselinux/src/label_support.c')
-rw-r--r--libselinux/src/label_support.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libselinux/src/label_support.c b/libselinux/src/label_support.c
index 324dc51c..26f9ef15 100644
--- a/libselinux/src/label_support.c
+++ b/libselinux/src/label_support.c
@@ -10,14 +10,19 @@
#include <string.h>
#include <stdio.h>
#include <errno.h>
+#include <errno.h>
#include "label_internal.h"
/*
- * The read_spec_entries and read_spec_entry functions may be used to
- * replace sscanf to read entries from spec files. The file and
- * property services now use these.
+ * Read an entry from a spec file (e.g. file_contexts)
+ * entry - Buffer to allocate for the entry.
+ * ptr - current location of the line to be processed.
+ * returns - 0 on success and *entry is set to be a null
+ * terminated value. On Error it returns -1 and
+ * errno will be set.
+ *
*/
-static inline int read_spec_entry(char **entry, char **ptr, int *len)
+static inline int read_spec_entry(char **entry, char **ptr, int *len, const char **errbuf)
{
*entry = NULL;
char *tmp_buf = NULL;
@@ -29,6 +34,11 @@ static inline int read_spec_entry(char **entry, char **ptr, int *len)
*len = 0;
while (!isspace(**ptr) && **ptr != '\0') {
+ if (!isascii(**ptr)) {
+ errno = EINVAL;
+ *errbuf = "Non-ASCII characters found";
+ return -1;
+ }
(*ptr)++;
(*len)++;
}
@@ -44,18 +54,23 @@ static inline int read_spec_entry(char **entry, char **ptr, int *len)
/*
* line_buf - Buffer containing the spec entries .
+ * errbuf - Double pointer used for passing back specific error messages.
* num_args - The number of spec parameter entries to process.
* ... - A 'char **spec_entry' for each parameter.
- * returns - The number of items processed.
+ * returns - The number of items processed. On error, it returns -1 with errno
+ * set and may set errbuf to a specific error message.
*
* This function calls read_spec_entry() to do the actual string processing.
+ * As such, can return anything from that function as well.
*/
-int hidden read_spec_entries(char *line_buf, int num_args, ...)
+int hidden read_spec_entries(char *line_buf, const char **errbuf, int num_args, ...)
{
char **spec_entry, *buf_p;
int len, rc, items, entry_len = 0;
va_list ap;
+ *errbuf = NULL;
+
len = strlen(line_buf);
if (line_buf[len - 1] == '\n')
line_buf[len - 1] = '\0';
@@ -85,7 +100,7 @@ int hidden read_spec_entries(char *line_buf, int num_args, ...)
return items;
}
- rc = read_spec_entry(spec_entry, &buf_p, &entry_len);
+ rc = read_spec_entry(spec_entry, &buf_p, &entry_len, errbuf);
if (rc < 0) {
va_end(ap);
return rc;