Changeset 567 in openpam for trunk/lib


Ignore:
Timestamp:
Apr 5, 2012, 2:32:51 PM (9 years ago)
Author:
Dag-Erling Smørgrav
Message:

Fix backslashes within single-quoted strings (no escape function)
Fix line continuation (newline is stripped, not quoted)
Further improve the documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/openpam_readword.c

    r553 r567  
    8080        escape = quote = 0;
    8181        while ((ch = fgetc(f)) != EOF && (!is_ws(ch) || quote || escape)) {
    82                 if (ch == '\\' && !escape) {
     82                if (ch == '\\' && !escape && quote != '\'') {
    8383                        /* escape next character */
    8484                        escape = ch;
     
    9797                        /* end quote */
    9898                        quote = 0;
     99                } else if (ch == '\n' && escape && !quote) {
     100                        /* line continuation */
     101                        escape = 0;
    99102                } else {
    100103                        if (escape && quote && ch != '\\' && ch != quote &&
     
    142145 *
    143146 *  - An unescaped single or double quote introduces a quoted string,
    144  *    which ends when the same quote character is encountered, unescaped,
    145  *    a second time.
     147 *    which ends when the same quote character is encountered a second
     148 *    time.
    146149 *    The quotes themselves are stripped.
    147150 *
     
    149152 *    including the newline character, are preserved as-is.
    150153 *
    151  *  - Outside a string, a backslash escapes the next character, which is
     154 *  - Outside a quoted string, a backslash escapes the next character,
     155 *    which is preserved as-is, unless that character is a newline, in
     156 *    which case it is discarded and reading continues at the beginning of
     157 *    the next line as if the backslash and newline had not been there.
     158 *    In all cases, the backslash itself is discarded.
     159 *
     160 *  - Within a single-quoted string, double quotes and backslashes are
    152161 *    preserved as-is.
    153  *    The backslash itself is stripped.
    154  *
    155  *  - Within a single-quoted string, a double quote is preserved as-is,
    156  *    and a backslash is preserved as-is unless used to escape a single
    157  *    quote.
    158162 *
    159163 *  - Within a double-quoted string, a single quote is preserved as-is,
     
    165169 * If a hash character occurs within a word, however, it is preserved
    166170 * as-is.
     171 * A backslash at the end of a comment does cause line continuation.
     172 *
     173 * If =lineno is not =NULL, the integer variable it points to is
     174 * incremented every time a quoted or escaped newline character is read.
     175 *
     176 * If =lenp is not =NULL, the length of the word (after quotes and
     177 * backslashes have been removed) is stored in the variable it points to.
     178 *
     179 *RETURN VALUES
     180 *
     181 * If successful, the =openpam_readword function returns a pointer to a
     182 * dynamically allocated NUL-terminated string containing the first word
     183 * encountered on the line.
     184 *
     185 * The caller is responsible for releasing the returned buffer by passing
     186 * it to =!free.
    167187 *
    168188 * If =openpam_readword reaches the end of the line or file before any
     
    174194 * =NULL.
    175195 *
    176  * If =lineno is not =NULL, the integer variable it points to is
    177  * incremented every time a quoted or escaped newline character is read.
    178  *
    179  * If =lenp is not =NULL, the length of the word (after quotes and
    180  * backslashes have been removed) is stored in the variable it points to.
    181  *
    182  * The caller is responsible for releasing the returned buffer by passing
    183  * it to =!free.
    184  *
    185196 *IMPLEMENTATION NOTES
    186197 *
    187  * The parsing rules are intended to be equivalent to those used by the
    188  * shell to parse a command line when =IFS is unset.
     198 * The parsing rules are intended to be equivalent to the normal POSIX
     199 * shell quoting rules.
    189200 * Any discrepancy is a bug and should be reported to the author along
    190201 * with sample input that can be used to reproduce the error.
Note: See TracChangeset for help on using the changeset viewer.