If the key names are not found in
the order listed, or trailing \n characters fail to be found, the input is considered malformed
and the function returns. Parsing the packet goes well until processing of the
optional environ values begins. The environ field is processed by the following code
(note, the pointer p at this point is positioned at the next character that needs parsing
within the input buffer):
envstrings[0] = NULL; //assume no environment strings
if (!strncmp("environ", p, strlen("environ"))) {
field = memchr(p, ' ', strlen(p)); //find trailing space
if (field == NULL) { //error if no trailing space
reply(id, "missing environment value", sock, addr);
return;
}
field++; //increment to first character of key
i = 0; //init our index counter into envstrings
while (1) { //loop as long as we need to
envstrings[i] = field; //save the next envstring ptr
p = memchr(field, ' ', strlen(field)); //trailing space
if (p == NULL) { //if no space then we need a newline
p = memchr(field, '\n', strlen(field));
if (p == NULL) {
reply(id, "malformed environment value", sock, addr);
return;
}
*p = '\0'; //found newline terminate last envstring
i++; //count the envstring
break; //newline marks the end so break
}
*p = '\0'; //terminate the envstring
field = p + 1; //point to start of next envstring
i++; //count the envstring
}
envstrings[i] = NULL; //terminate the list
}
Following the processing of the environ field, each pointer in the envstrings array is
passed to the putenv() function, so these strings are expected to be in the form key=
value.
Pages:
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522