| 318 | } |
| 319 | |
| 320 | static void |
| 321 | init_dynamic_kenv_from(char *init_env, int *curpos) |
| 322 | { |
| 323 | char *cp, *cpnext, *eqpos, *found; |
| 324 | size_t len; |
| 325 | int i; |
| 326 | |
| 327 | if (init_env && *init_env != '\0') { |
| 328 | found = NULL; |
| 329 | i = *curpos; |
| 330 | for (cp = init_env; cp != NULL; cp = cpnext) { |
| 331 | cpnext = kernenv_next(cp); |
| 332 | len = strlen(cp) + 1; |
| 333 | if (len > KENV_MNAMELEN + 1 + kenv_mvallen + 1) { |
| 334 | printf( |
| 335 | "WARNING: too long kenv string, ignoring %s\n", |
| 336 | cp); |
| 337 | goto sanitize; |
| 338 | } |
| 339 | eqpos = strchr(cp, '='); |
| 340 | if (eqpos == NULL) { |
| 341 | printf( |
| 342 | "WARNING: malformed static env value, ignoring %s\n", |
| 343 | cp); |
| 344 | goto sanitize; |
| 345 | } |
| 346 | *eqpos = 0; |
| 347 | /* |
| 348 | * De-dupe the environment as we go. We don't add the |
| 349 | * duplicated assignments because config(8) will flip |
| 350 | * the order of the static environment around to make |
| 351 | * kernel processing match the order of specification |
| 352 | * in the kernel config. |
| 353 | */ |
| 354 | found = _getenv_dynamic_locked(cp, NULL); |
| 355 | *eqpos = '='; |
| 356 | if (found != NULL) |
| 357 | goto sanitize; |
| 358 | if (i > KENV_SIZE) { |
| 359 | printf( |
| 360 | "WARNING: too many kenv strings, ignoring %s\n", |
| 361 | cp); |
| 362 | goto sanitize; |
| 363 | } |
| 364 | |
| 365 | kenvp[i] = malloc(len, M_KENV, M_WAITOK); |
| 366 | strcpy(kenvp[i++], cp); |
| 367 | sanitize: |
| 368 | explicit_bzero(cp, len - 1); |
| 369 | } |
| 370 | *curpos = i; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Setup the dynamic kernel environment. |
no test coverage detected