﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
2435	static locations longer than 255 characters lead to unexpected behaviors	Max Laverse		"**Description**
Defining `location`s with paths longer than 255 characters leads to unexpected behaviors with some or almost all locations being ignored.

**Probable Root Cause**
When Nginx starts, it copies the `location`s read from the configuration into a tree. The locations are initially stored in a structure allowing large strings, but once copied in `ngx_http_create_locations_tree()`, the variable holding the length of the location is cast to an `u_char`. For static locations having a long path, the original size is eventually altered leading to a misrepresentation of the data and unexpected results.
 

**How to reproduce**
Using the following configuration:
{{{
daemon off;
master_process off;
error_log /dev/stderr debug;

events {
  worker_connections 4096;
}

http {
  server {
    server_name localhost;

    location = /43210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321 {
      return 200;
    }

    location = /543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321 {
      return 200;
    }

    location = /6543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321 {
      return 200;
    }

    location / {
      return 500;
    }
  }
}
}}}

The expected result would be 200 if you call any of the first 3 URLs. The actual result in my environment is 200, 200, 500.

If I add this additional block:

{{{
location = /76543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321 {
  return 200;
}
}}}

all URLs now returns 500.

"	defect	closed	minor		documentation	1.23.x	fixed		Max Laverse	Darwin Maximes-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64	"nginx version: nginx/1.23.4
built by clang 14.0.0 (clang-1400.0.29.202)
configure arguments: --with-debug"
