#1557 closed defect (fixed)

Extra spaces should not cause nginx error

Reported by: gfrankliu@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.14.x
Keywords: Cc:
uname -a:
nginx -V: 1.14.0

Description

Shouldn't nginx just ignore those extra spaces and blank lines?

I tried below in the config of nginx 1.14.0:

server {
...

set $testvar1 "testval1";

... 300 blank lines, each with 20 spaces ...

set $testvar2 "testval2";

...
}

nginx configtest says:
nginx: [emerg] too long parameter "

..." started in

Change History (6)

comment:1 Changed 16 months ago by mdounin

  • Status changed from new to accepted

Please try the following patch:

# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1532225835 -10800
#      Sun Jul 22 05:17:15 2018 +0300
# Node ID 1fd68b8ceede5ad560e4b15ccad5919b6f4e179e
# Parent  d230c797b1686c5f353295c4093a45222b811ad6
Skipping spaces in configuration files (ticket #1557).

Previously, a chunk of spaces larger than NGX_CONF_BUFFER (4096 bytes)
resulted in the "too long parameter" error during parsing such a
configuration.  This was because the code only set start and start_line
on non-whitespace characters, and hence adjacent whitespace characters
were preserved when reading additional data from the configuration file.
Fix is to always move start and start_line if the last character was
a space.

diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -656,13 +656,14 @@ ngx_conf_read_token(ngx_conf_t *cf)
         }
 
         if (last_space) {
+
+            start = b->pos - 1;
+            start_line = cf->conf_file->line;
+
             if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                 continue;
             }
 
-            start = b->pos - 1;
-            start_line = cf->conf_file->line;
-
             switch (ch) {
 
             case ';':

comment:2 Changed 16 months ago by gfrankliu@…

Tried 1.15.2 released this morning and the error is still there.
Manually applied above patch, and the error goes away.

comment:3 Changed 16 months ago by gfrankliu@…

Tested the patch and it works.
Thanks and you can close this ticket.

comment:4 Changed 16 months ago by mdounin

Thanks for testing, the patch was submitted for an internal review. Once reviewed, the patch will be committed, and then this ticket will be closed.

comment:5 Changed 16 months ago by Maxim Dounin <mdounin@…>

In 7334:f17e313009b0/nginx:

Skipping spaces in configuration files (ticket #1557).

Previously, a chunk of spaces larger than NGX_CONF_BUFFER (4096 bytes)
resulted in the "too long parameter" error during parsing such a
configuration. This was because the code only set start and start_line
on non-whitespace characters, and hence adjacent whitespace characters
were preserved when reading additional data from the configuration file.
Fix is to always move start and start_line if the last character was
a space.

comment:6 Changed 16 months ago by mdounin

  • Resolution set to fixed
  • Status changed from accepted to closed

Committed, thanks.

Note: See TracTickets for help on using tickets.