Index: src/backend/libpq/hba.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v retrieving revision 1.119 diff -c -r1.119 hba.c *** src/backend/libpq/hba.c 25 Dec 2003 03:44:04 -0000 1.119 --- src/backend/libpq/hba.c 1 Feb 2004 17:17:34 -0000 *************** *** 105,187 **** while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ',')) ; ! if (c != EOF && c != '\n') { ! /* ! * Build a token in buf of next characters up to EOF, EOL, ! * unquoted comma, or unquoted whitespace. ! */ ! while (c != EOF && c != '\n' && ! (!pg_isblank(c) || in_quote == true)) { ! /* skip comments to EOL */ ! if (c == '#' && !in_quote) ! { ! while ((c = getc(fp)) != EOF && c != '\n') ! ; ! /* If only comment, consume EOL too; return EOL */ ! if (c != EOF && buf == start_buf) ! c = getc(fp); ! break; ! } ! ! if (buf >= end_buf) ! { ! ereport(LOG, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), ! errmsg("authentication file token too long, skipping: \"%s\"", ! buf))); ! /* Discard remainder of line */ ! while ((c = getc(fp)) != EOF && c != '\n') ! ; ! buf[0] = '\0'; ! break; ! } ! ! if (c != '"' || (c == '"' && was_quote)) ! *buf++ = c; ! ! /* We pass back the comma so the caller knows there is more */ ! if ((pg_isblank(c) || c == ',') && !in_quote) ! break; ! ! /* Literal double-quote is two double-quotes */ ! if (in_quote && c == '"') ! was_quote = !was_quote; ! else ! was_quote = false; ! ! if (c == '"') ! { ! in_quote = !in_quote; ! saw_quote = true; ! } ! c = getc(fp); } ! /* ! * Put back the char right after the token (critical in case it is ! * EOL, since we need to detect end-of-line at next call). ! */ ! if (c != EOF) ! ungetc(c, fp); } if ( !saw_quote && ( ! strncmp(start_buf,"all",3) == 0 || ! strncmp(start_buf,"sameuser",8) == 0 || ! strncmp(start_buf,"samegroup",9) == 0 ) ) { /* append newline to a magical keyword */ *buf++ = '\n'; } - *buf = '\0'; } --- 105,191 ---- while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ',')) ; ! if (c == EOF || c == '\n') { ! *buf = '\0'; ! return; ! } ! ! /* ! * Build a token in buf of next characters up to EOF, EOL, ! * unquoted comma, or unquoted whitespace. ! */ ! while (c != EOF && c != '\n' && ! (!pg_isblank(c) || in_quote == true)) ! { ! /* skip comments to EOL */ ! if (c == '#' && !in_quote) { ! while ((c = getc(fp)) != EOF && c != '\n') ! ; ! /* If only comment, consume EOL too; return EOL */ ! if (c != EOF && buf == start_buf) ! c = getc(fp); ! break; ! } ! if (buf >= end_buf) ! { ! ereport(LOG, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), ! errmsg("authentication file token too long, skipping: \"%s\"", ! buf))); ! /* Discard remainder of line */ ! while ((c = getc(fp)) != EOF && c != '\n') ! ; ! buf[0] = '\0'; ! break; } ! if (c != '"' || (c == '"' && was_quote)) ! *buf++ = c; ! ! /* We pass back the comma so the caller knows there is more */ ! if ((pg_isblank(c) || c == ',') && !in_quote) ! break; ! ! /* Literal double-quote is two double-quotes */ ! if (in_quote && c == '"') ! was_quote = !was_quote; ! else ! was_quote = false; ! ! if (c == '"') ! { ! in_quote = !in_quote; ! saw_quote = true; ! } ! ! c = getc(fp); } + /* + * Put back the char right after the token (critical in case it is + * EOL, since we need to detect end-of-line at next call). + */ + if (c != EOF) + ungetc(c, fp); + + *buf = '\0'; if ( !saw_quote && ( ! strcmp(start_buf,"all") == 0 || ! strcmp(start_buf,"sameuser") == 0 || ! strcmp(start_buf,"samegroup") == 0 ) ) { /* append newline to a magical keyword */ *buf++ = '\n'; + *buf = '\0'; } }