...
| Code Block | ||
|---|---|---|
| ||
static int yy_string_get() {
register char *string;
register int c;
string = bash_input.location.string;
c = EOF;
/* If the string doesn't exist, or is empty, EOF found. */
if (string && *string) {
c = *string++;
bash_input.location.string = string;
}
return (c);
}
|
The string variable is used to traverse the character string containing the command line to be parsed. As characters are retrieved from this pointer, they are stored in a variable of type int. For compilers in which the char type defaults to signed char, this value is sign-extended when assigned to the int variable. For character code 255 decimal (-1 in two's complement form), this sign extension results in the value -1 being assigned to the integer, which is indistinguishable from EOF.
...
| Code Block | ||
|---|---|---|
| ||
static int yy_string_get() {
register unsigned char *string;
register int c;
string = bash_input.location.string;
c = EOF;
/* If the string doesn't exist, or is empty, EOF found. */
if (string && *string) {
c = *string++;
bash_input.location.string = string;
}
return (c);
}
|
This solution, however, is in violation of STR04-A. Use plain char for characters in the basic character set.
...
| Code Block | ||
|---|---|---|
| ||
static int yy_string_get() {
register char *string;
register int c;
string = bash_input.location.string;
c = EOF;
/* If the string doesn't exist, or is empty, EOF found. */
if (string && *string) {
/* cast to unsigned type */
c = (unsigned char)*string++;
bash_input.location.string = string;
}
return (c);
}
|
Risk Assessment
...