From 0f912a1cd9dc2c7bb7aebf40d4a0b58058a2a4ac Mon Sep 17 00:00:00 2001 From: Stephen Smalley Date: Fri, 13 Feb 2015 14:08:57 -0500 Subject: libselinux: Reject duplicate keys in seapp_context entries. Presently it will leak the memory from the first definition and use the last one in each line. Treat it as an error instead and fail. Change-Id: I6a6383bf6ace59b1fd504c01047fd685c16c4849 Signed-off-by: Stephen Smalley --- src/android.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/android.c b/src/android.c index 8e39aac..7773489 100644 --- a/src/android.c +++ b/src/android.c @@ -366,6 +366,10 @@ int selinux_android_seapp_context_reload(void) goto err; } } else if (!strcasecmp(name, "user")) { + if (cur->user.str) { + free_seapp_context(cur); + goto err; + } cur->user.str = strdup(value); if (!cur->user.str) { free_seapp_context(cur); @@ -375,12 +379,20 @@ int selinux_android_seapp_context_reload(void) if (cur->user.str[cur->user.len-1] == '*') cur->user.is_prefix = 1; } else if (!strcasecmp(name, "seinfo")) { + if (cur->seinfo) { + free_seapp_context(cur); + goto err; + } cur->seinfo = strdup(value); if (!cur->seinfo) { free_seapp_context(cur); goto oom; } } else if (!strcasecmp(name, "name")) { + if (cur->name.str) { + free_seapp_context(cur); + goto err; + } cur->name.str = strdup(value); if (!cur->name.str) { free_seapp_context(cur); @@ -390,18 +402,30 @@ int selinux_android_seapp_context_reload(void) if (cur->name.str[cur->name.len-1] == '*') cur->name.is_prefix = 1; } else if (!strcasecmp(name, "domain")) { + if (cur->domain) { + free_seapp_context(cur); + goto err; + } cur->domain = strdup(value); if (!cur->domain) { free_seapp_context(cur); goto oom; } } else if (!strcasecmp(name, "type")) { + if (cur->type) { + free_seapp_context(cur); + goto err; + } cur->type = strdup(value); if (!cur->type) { free_seapp_context(cur); goto oom; } } else if (!strcasecmp(name, "levelFromUid")) { + if (cur->levelFrom) { + free_seapp_context(cur); + goto err; + } if (!strcasecmp(value, "true")) cur->levelFrom = LEVELFROM_APP; else if (!strcasecmp(value, "false")) @@ -411,6 +435,10 @@ int selinux_android_seapp_context_reload(void) goto err; } } else if (!strcasecmp(name, "levelFrom")) { + if (cur->levelFrom) { + free_seapp_context(cur); + goto err; + } if (!strcasecmp(value, "none")) cur->levelFrom = LEVELFROM_NONE; else if (!strcasecmp(value, "app")) @@ -424,12 +452,20 @@ int selinux_android_seapp_context_reload(void) goto err; } } else if (!strcasecmp(name, "level")) { + if (cur->level) { + free_seapp_context(cur); + goto err; + } cur->level = strdup(value); if (!cur->level) { free_seapp_context(cur); goto oom; } } else if (!strcasecmp(name, "path")) { + if (cur->path.str) { + free_seapp_context(cur); + goto err; + } cur->path.str = strdup(value); if (!cur->path.str) { free_seapp_context(cur); -- cgit v1.2.3