| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * be found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
| 11 | 11 |
| 12 #include "native_client/src/trusted/service_runtime/env_cleanser.h" | 12 #include "native_client/src/trusted/service_runtime/env_cleanser.h" |
| 13 #include "native_client/src/trusted/service_runtime/env_cleanser_test.h" | 13 #include "native_client/src/trusted/service_runtime/env_cleanser_test.h" |
| 14 | 14 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 34 "FOOBAR", | 34 "FOOBAR", |
| 35 "LC_TIME=%a, %B %d, %Y", | 35 "LC_TIME=%a, %B %d, %Y", |
| 36 "QUUX", | 36 "QUUX", |
| 37 "USER=bsy", | 37 "USER=bsy", |
| 38 "LC_PAPER=en_US.UTF-8@legal", | 38 "LC_PAPER=en_US.UTF-8@legal", |
| 39 "HOME=/home/bsy", | 39 "HOME=/home/bsy", |
| 40 "PATH=/home/bsy/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", | 40 "PATH=/home/bsy/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", |
| 41 "LANG=en_us.UTF-8", | 41 "LANG=en_us.UTF-8", |
| 42 "LC_MEASUREMENT=en_US.UTF-8", | 42 "LC_MEASUREMENT=en_US.UTF-8", |
| 43 "LD_LIBRARY_PATH=.:/usr/bsy/lib", | 43 "LD_LIBRARY_PATH=.:/usr/bsy/lib", |
| 44 "NACLENV_LD_PRELOAD=libvalgrind.so", |
| 45 "NACLENV_SHELL=/bin/sh", |
| 44 NULL, | 46 NULL, |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 static char const *const kFilteredEnv[] = { | 49 static char const *const kFilteredEnv[] = { |
| 48 "LANG=en_us.UTF-8", | 50 "LANG=en_us.UTF-8", |
| 49 "LC_MEASUREMENT=en_US.UTF-8", | 51 "LC_MEASUREMENT=en_US.UTF-8", |
| 50 "LC_PAPER=en_US.UTF-8@legal", | 52 "LC_PAPER=en_US.UTF-8@legal", |
| 51 "LC_TIME=%a, %B %d, %Y", | 53 "LC_TIME=%a, %B %d, %Y", |
| 54 "LD_PRELOAD=libvalgrind.so", |
| 55 "SHELL=/bin/sh", |
| 56 NULL, |
| 57 }; |
| 58 |
| 59 static char const *const kFilteredEnvWithoutWhitelist[] = { |
| 60 "LD_PRELOAD=libvalgrind.so", |
| 61 "SHELL=/bin/sh", |
| 52 NULL, | 62 NULL, |
| 53 }; | 63 }; |
| 54 | 64 |
| 55 int StrInStrTbl(char const *str, char const *const *tbl) { | 65 int StrInStrTbl(char const *str, char const *const *tbl) { |
| 56 int i; | 66 int i; |
| 57 | 67 |
| 58 for (i = 0; NULL != tbl[i]; ++i) { | 68 for (i = 0; NULL != tbl[i]; ++i) { |
| 59 if (!strcmp(str, tbl[i])) { | 69 if (!strcmp(str, tbl[i])) { |
| 60 return 1; | 70 return 1; |
| 61 } | 71 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 printf("Checking %s\n", kValidEnvs[i]); | 153 printf("Checking %s\n", kValidEnvs[i]); |
| 144 if (0 == NaClEnvInWhitelist(kValidEnvs[i])) { | 154 if (0 == NaClEnvInWhitelist(kValidEnvs[i])) { |
| 145 ++errors; | 155 ++errors; |
| 146 printf("ERROR\n"); | 156 printf("ERROR\n"); |
| 147 } else { | 157 } else { |
| 148 printf("OK\n"); | 158 printf("OK\n"); |
| 149 } | 159 } |
| 150 } | 160 } |
| 151 | 161 |
| 152 printf("\nEnvironment Filtering\n"); | 162 printf("\nEnvironment Filtering\n"); |
| 153 NaClEnvCleanserCtor(&nec); | 163 NaClEnvCleanserCtor(&nec, 1); |
| 154 if (!NaClEnvCleanserInit(&nec, kMurkyEnv)) { | 164 if (!NaClEnvCleanserInit(&nec, kMurkyEnv, NULL)) { |
| 155 printf("FAILED: NaClEnvCleanser Init failed\n"); | 165 printf("FAILED: NaClEnvCleanser Init failed\n"); |
| 156 ++errors; | 166 ++errors; |
| 157 } else { | 167 } else { |
| 158 if (!StrTblsHaveSameEntries(NaClEnvCleanserEnvironment(&nec), | 168 if (!StrTblsHaveSameEntries(NaClEnvCleanserEnvironment(&nec), |
| 159 kFilteredEnv)) { | 169 kFilteredEnv)) { |
| 160 printf("ERROR: filtered env wrong\n"); | 170 printf("ERROR: filtered env wrong\n"); |
| 161 ++errors; | 171 ++errors; |
| 162 | 172 |
| 163 PrintStrTbl("Original environment", kMurkyEnv); | 173 PrintStrTbl("Original environment", kMurkyEnv); |
| 164 PrintStrTbl("Filtered environment", NaClEnvCleanserEnvironment(&nec)); | 174 PrintStrTbl("Filtered environment", NaClEnvCleanserEnvironment(&nec)); |
| 165 PrintStrTbl("Expected environment", kFilteredEnv); | 175 PrintStrTbl("Expected environment", kFilteredEnv); |
| 166 } else { | 176 } else { |
| 167 printf("OK\n"); | 177 printf("OK\n"); |
| 168 } | 178 } |
| 169 } | 179 } |
| 170 NaClEnvCleanserDtor(&nec); | 180 NaClEnvCleanserDtor(&nec); |
| 171 | 181 |
| 182 printf("\nEnvironment Filtering (without whitelist)\n"); |
| 183 NaClEnvCleanserCtor(&nec, 0); |
| 184 if (!NaClEnvCleanserInit(&nec, kMurkyEnv, NULL)) { |
| 185 printf("FAILED: NaClEnvCleanser Init failed\n"); |
| 186 ++errors; |
| 187 } else { |
| 188 if (!StrTblsHaveSameEntries(NaClEnvCleanserEnvironment(&nec), |
| 189 kFilteredEnvWithoutWhitelist)) { |
| 190 printf("ERROR: filtered env wrong\n"); |
| 191 ++errors; |
| 192 |
| 193 PrintStrTbl("Original environment", kMurkyEnv); |
| 194 PrintStrTbl("Filtered environment", NaClEnvCleanserEnvironment(&nec)); |
| 195 PrintStrTbl("Expected environment", kFilteredEnvWithoutWhitelist); |
| 196 } else { |
| 197 printf("OK\n"); |
| 198 } |
| 199 } |
| 200 NaClEnvCleanserDtor(&nec); |
| 201 |
| 172 printf("%s\n", (0 == errors) ? "PASSED" : "FAILED"); | 202 printf("%s\n", (0 == errors) ? "PASSED" : "FAILED"); |
| 173 return 0 != errors; | 203 return 0 != errors; |
| 174 } | 204 } |
| OLD | NEW |