Quantcast
Channel: Nginx Forum
Viewing all 53287 articles
Browse latest View live

Re: nginx for Windows - WSASend() socket error 10057

$
0
0
I don't know what is wrong with your config... I guess your smtp server
does not answer properly.

Is 127.0.0.2:143 really your SMTP-server?
Because port 143 is mostly an IMAP port - but you've specified PROTOCOL
SMTP in the server section.

Anyway I tested your config with my settings (replaced name and
smtp-server, here 192.0.2.222:25) and enabled debug:

+ error_log logs/error-mail.log DEBUG;
mail {
- server_name localhost;
+ server_name EXAMPLE.COM;
....
http {
....
- add_header Auth-Server 127.0.0.2;
- add_header Auth-Port 143;
+ add_header Auth-Server 192.0.2.222;
+ add_header Auth-Port 25;

it works well - I see the test incoming mail (I send to myself via 8025
port) and following output in the log (a lot of irrelevant messages are
removed):

>>>>>>>>>

2020/02/14 11:24:04 [debug] 121280#128244: *1 smtp mail from:"mail
FROM:<test@example.com>"
....
2020/02/14 11:24:04 [debug] 121280#128244: *3 http request line: "GET
/cgi-bin/nginxauth.cgi HTTP/1.0"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http uri:
"/cgi-bin/nginxauth.cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http args: ""
2020/02/14 11:24:04 [debug] 121280#128244: *3 http exten: "cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http process request
header line
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Host:
localhost"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Method:
none"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-User: "
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Pass: "
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header:
"Auth-Protocol: smtp"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header:
"Auth-Login-Attempt: 1"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Client-IP:
127.0.0.1"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Client-Host:
[UNAVAILABLE]"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header:
"Auth-SMTP-Helo: myhost.example.com"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header:
"Auth-SMTP-From: mail FROM:<test@example.com>"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header:
"Auth-SMTP-To: rcpt TO:<test@example.com>"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header done
2020/02/14 11:24:04 [debug] 121280#128244: *3 event timer del: 512:
1127939767
2020/02/14 11:24:04 [debug] 121280#128244: *3 generic phase: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 rewrite phase: 1
2020/02/14 11:24:04 [debug] 121280#128244: *3 search through nested
static locations of ""
2020/02/14 11:24:04 [debug] 121280#128244: *3 test location:
"/cgi-bin/nginxauth.cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 using configuration
"/cgi-bin/nginxauth.cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http cl:-1 max:1048576
2020/02/14 11:24:04 [debug] 121280#128244: *3 rewrite phase: 3
2020/02/14 11:24:04 [debug] 121280#128244: *3 http set discard body
2020/02/14 11:24:04 [debug] 121280#128244: *3 HTTP/1.1 204 No Content
Server: nginx/1.17.4
Date: Fri, 14 Feb 2020 10:24:04 GMT
Connection: close
Auth-Status: OK
Auth-Server: 192.0.2.222
Auth-Port: 25

2020/02/14 11:24:04 [debug] 121280#128244: *3 write new buf t:1 f:0
008AD6A0, pos 008AD6A0, size: 164 file: 0, size: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter: l:1 f:0
s:164
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter limit 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 WSASend: fd:512, s:164
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter 00000000
2020/02/14 11:24:04 [debug] 121280#128244: *3 http finalize request: 0,
"/cgi-bin/nginxauth.cgi?" a:1, c:1
2020/02/14 11:24:04 [debug] 121280#128244: *3 http request count:1 blk:0
2020/02/14 11:24:04 [debug] 121280#128244: *3 http close request
2020/02/14 11:24:04 [debug] 121280#128244: *3 http log handler
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 008ACC50, unused:
1161
2020/02/14 11:24:04 [debug] 121280#128244: *3 close http connection: 512
2020/02/14 11:24:04 [debug] 121280#128244: *3 reusable connection: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 008AC848
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 0039FDE0, unused: 28
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http read
handler
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 164
of 1024
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http process
status line
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http process
headers
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Server: nginx/1.17.4"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Date: Fri, 14 Feb 2020 10:24:04 GMT"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Connection: close"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Auth-Status: OK"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Auth-Server: 192.0.2.222"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header:
"Auth-Port: 25"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header done
2020/02/14 11:24:04 [debug] 121280#128244: *1 event timer del: 496:
1127939764
2020/02/14 11:24:04 [debug] 121280#128244: *1 reusable connection: 0
2020/02/14 11:24:04 [debug] 121280#128244: *1 free: 008AC040, unused:
196
2020/02/14 11:24:04 [debug] 121280#128244: *1 stream socket 496
2020/02/14 11:24:04 [debug] 121280#128244: *1 connect to 192.0.2.222:25,
fd:496 #4
2020/02/14 11:24:04 [debug] 121280#128244: *1 event timer add: 496:
60000:1127939769
2020/02/14 11:24:04 [debug] 121280#128244: *1 malloc: 008AC040:4096
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 post event 00897120
2020/02/14 11:24:04 [debug] 121280#128244: posted event 00897120
2020/02/14 11:24:04 [debug] 121280#128244: *1 delete posted event
00897120
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy dummy handler
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy smtp auth
handler
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 22 of
4096
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy send ehlo
2020/02/14 11:24:04 [debug] 121280#128244: *1 malloc: 0039FDE0:256
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSASend: fd:496, 0, 25 of
25
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth
handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 196
of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy send mail from
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 47 of
47
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth
handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 60 of
4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy send rcpt to
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 45 of
45
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth
handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 63 of
4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer add: 492:
86400000:1214280441
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer del: 496:
1127939769
2020/02/14 11:24:05 [info] 121280#128244: *1 client logged in, client:
127.0.0.1, server: 0.0.0.0:8025
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 1,
#496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 63 of
63
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old:
1214280441, new: 1214280441
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 post event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 delete posted event
008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0,
#492 > #496
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:492 rc:0 6 of
4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 6 of 6
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old:
1214280441, new: 1214280441
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0,
#496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 50 of
4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 50 of
50
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 post event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 delete posted event
008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0,
#492 > #496
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:492 rc:0 170
of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 170 of
170
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old:
1214280441, new: 1214280535
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0,
#496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 56 of
4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 56 of
56
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
....

<<<<<<<<<

Regards,
Sergey

13.02.2020 22:45, Yury Shpakov wrote:

> Hi Sergey,
>
> I reconfigured the config file as follows:
>
> === === ===
>
> #user nobody;
> worker_processes 1;
>
> #error_log logs/error.log;
> #error_log logs/error.log notice;
> #error_log logs/error.log info;
>
> #pid logs/nginx.pid;
>
> events {
> worker_connections 1024;
> }
>
> mail {
> server_name localhost;
> auth_http localhost:9000/cgi-bin/nginxauth.cgi;
> # auth_http none;
>
> smtp_auth none;
> # smtp_auth login plain cram-md5;
> # smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
> xclient off;
>
> server {
> listen 8025;
> protocol smtp;
> proxy on;
> proxy_pass_error_message on;
> }
> }
>
> http {
> server {
> listen 9000;
>
> location /cgi-bin/nginxauth.cgi {
> add_header Auth-Status OK;
> add_header Auth-Server 127.0.0.2; # backend ip
> add_header Auth-Port 143; # backend port
> return 204;
> }
> }
> }
> === === ===
>
> And now it's responding on port 9000 as expected:
>
> === === ===
> C:WINDOWSsystem32>curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi
>
> HTTP/1.1 204 No Content
> Server: nginx/1.17.9
> Date: Thu, 13 Feb 2020 21:30:54 GMT
> Connection: keep-alive
> Auth-Status: OK
> Auth-Server: 127.0.0.2 Auth-Port: 143
> === === ===
>
> However I'm still experiencing the same issue (in log file):
>
> === === ===
> 2020/02/13 16:29:24 [notice] 35048#26192: signal process started
>
> 2020/02/13 16:29:34 [error] 31732#22720: *1 WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025 === === ===
>
> Tried under both admin and regular user.
>
> Any further ideas how to get it fixed please?
>
> Thank you,
> Yury
>
> -------------------------
>
> FROM: Sergey Brester <serg.brester@sebres.de>
> SENT: Wednesday, February 12, 2020 1:51 PM
> TO: Yury Shpakov <yshpakov@hotmail.com>
> CC: nginx-devel@nginx.org <nginx-devel@nginx.org>
> SUBJECT: Re: nginx for Windows - WSASend() socket error 10057
>
> I answered inline...
>
> 12.02.2020 18:59, Yury Shpakov wrote:
>
>> Hi Sergey,
>>
>> Thank you for you response.
>>
>> I tried netstat /nabo and I don't see any reference to port 9000 at all.
>> So a problem is to make nginx to listen on port 9000 (as server)?
>> Or nginx is not listening on port 9000 but rather sending requests to port 9000 (as client)?
>
> With setting of `auth_http`, you are defining an URL to the service responsible for authentication (and upstream choice).
> Of course then you should have something that would response to the auth-requests (your own upstream, or some nginx location, or some "foreign" http-server).
>
> See https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/ [2] for more examples.
>
>> Maybe it's easier not to use auth_http at all? I was trying to remove it from configuration file but nginx was not happy.
>
> I have my own auth-module so I don't know how it can be solved in stock-nginx without this directive.
>
> Take a look here - https://serverfault.com/questions/594962/nginx-understanding-the-purpose-of-auth-http-imap-proxy [3] - you can use some nginx location (and internal URL to same nginx instance) to specify that.
>
> Anyway it is recommended to use some auth (on nginx side), because it'd preserve the resources of mail-servers, allow you to authenticate email clients with same user/password for all mail-servers (smtp, imap, pop3, etc) as well as the same user/pwd as for some other http-services. And it is used to choose an upstream server (if multiple) for the email processing.
>
>> At this point I don't need any authentication. I was told by my boss to use nginx for load testing of our service sending emails (SMTP client). I've got some SMTP Server and nginx would be used as SMTP proxy because it allows to set up delays.
>
> Well, an auth request to some nginx-location would allow you to set up delays even on authentication phase.
>
>> And take into account that I REMOVED "--with-http_ssl_module" from parameters when I was building nginx.
>>
>> And you advised to download some nginx.exe files but I believe they were built without "--with-mail" parameter (which I need).
>
> Although, it was compiled with "--with-mail" (you can see all parameters in provided GH-link [4])
> But it would not help, because basically your issue seems to be the configuration (not the nginx.exe).
>
> Thank you,
> Yury
>
> -------------------------
>
> FROM: Sergey Brester <serg.brester@sebres.de>
> SENT: Wednesday, February 12, 2020 7:38 AM
> TO: nginx-devel@nginx.org <nginx-devel@nginx.org>
> CC: Yury Shpakov <yshpakov@hotmail.com>
> SUBJECT: Re: nginx for Windows - WSASend() socket error 10057
>
> It looks like your service defined in auth_http doesn't answer (or no listener on 127.0.0.1 port 9000?)...
>
> try netstat (in cmd as admin):
>
> netstat /nabo
> netstat /nabo | grep -A 1 ":9000b"
>
> and check whether the listener on port 9000 is bound to 127.0.0.1 (or it is 0.0.0.0 only?) and it is the process you expect to see there (can be "reserved" by some other windows-service).
>
> additionally try to telnet or curl it:
>
> curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi
>
> if it does not answer, make another attempt by replace 127.0.0.1 with 0.0.0.0 (or a host-name).
>
> If it answers - see whether it is the expected response (some examples of good and bad responses are described in http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html [5]).
>
> But I guess if WSASend fails, it would probably (unexpected) reject the connection during the send (or even connect) process.
> It can be also invalid (unexpected) content-length in keep-alive connect to auth-upstream - so send but still receive is expected (or vice versa).
>
> Also follow this forum topic addressing similar issue: https://forum.nginx.org/read.php?2,257206,257207#msg-257207 [6]
>
> Anyway it doesn't look to me like an issue of nginx (regardless windows or not), but you can also try some other ready build (for example on my GH [4] - nginx.zip [7], where it works well).
>
> Regards,
> Sergey
>
> 12.02.2020 03:01, Yury Shpakov wrote:
> Hi there,
>
> Trying to make nginx work as SMTP server and/or SMTP proxy. Done everything according to:
> http://nginx.org/en/docs/howto_build_on_win32.html [8]
> But excluded (don't care about SSL at this point so don't want to install/configure Perl now):
> --with-openssl=objs/lib/openssl-master
>
> --with-openssl-opt=no-asm
> --with-http_ssl_module
> And added:
> --with-mail
>
> nmake was successful and nginx.exe was created.
> However nginx.exe keeps failing with the error:
> WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
> Windows API says the following about this error:
>
> WSAENOTCONN10057
> Socket is not connected.A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using SENDTO [9]) no address was supplied. Any other type of operation might also return this error--for example, SETSOCKOPT [10] setting SO_KEEPALIVE [11] if the connection has been reset.
>
> https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 [12]
>
> Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docs [12]
> Return code/value Description; WSA_INVALID_HANDLE 6: Specified event object handle is invalid. An application attempts to use an event object, but the specified handle is not valid.
> docs.microsoft.com
>
> Managed to debug your code in VS 2010 a little bit but it's brutal C so it's hard to figure your code out. And this debugger doesn't show you any local variables values.
> Any recommendation for me to make it work?
> Tried to play with config (commenting/uncommenting):
>
> #user nobody;
> worker_processes 1;
> #error_log logs/error.log;
> #error_log logs/error.log notice;
> #error_log logs/error.log info;
> #pid logs/nginx.pid;
> events {
> worker_connections 1024;
> }
> mail {
> server_name localhost;
> auth_http localhost:9000/cgi-bin/nginxauth.cgi;
> # auth_http none;
> smtp_auth none;
> # smtp_auth login plain cram-md5;
> # smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
> xclient off;
> server {
> listen 8025;
> protocol smtp;
> proxy on;
> proxy_pass_error_message on;
> }
> } Tried both under a regular user and under admin. Tried on 25, 1025 and 8025 ports.
> Thank you,
> Yury
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.orghttp://mailman.nginx.org/mailman/listinfo/nginx-devel [1]


Links:
------
[1] http://mailman.nginx.org/mailman/listinfo/nginx-devel
[2] https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/
[3]
https://serverfault.com/questions/594962/nginx-understanding-the-purpose-of-auth-http-imap-proxy
[4] https://github.com/sebres/nginx/releases/tag/release-1.13.0
[5] http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html
[6] https://forum.nginx.org/read.php?2,257206,257207#msg-257207
[7] https://github.com/sebres/nginx/files/2246440/nginx.zip
[8] http://nginx.org/en/docs/howto_build_on_win32.html
[9]
https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-sendto
[10]
https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-setsockopt
[11]
https://docs.microsoft.com/en-us/windows/desktop/winsock/so-keepalive
[12]
https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: [PATCH] Fix for the HT on request headers problem (#1752)

$
0
0
Hello,

Is there any update about this one, or it is a closed case for the Nginx
team?

Best Regards
Marin

On Fri, Jan 24, 2020 at 9:07 AM Marin Stavrev <mstavrev@gmail.com> wrote:

> Hello,
>
> I can understand your point, but still RFC 7230 defines OWS to allow HTAB
> and the therm used to suggest a single SP is SHOULD (recommendation) not
> MUST (mandatory). Thus, Nginx is not fully compliant.
> I would never post such a change if it wasn't really needed - I am not
> pushing for this change just out of love for RFC compliance.I have this
> issue causing problems with some Chinese IP cameras and NVRs that are
> generating such headers. I understand this is quite rare, and to be frank
> this is the only case I had personally seen such a (lousy) HTTP
> implementation. Unfortunately, I don't have any control over their FW and
> thus needed this fix on the server side.
> I know it does not matter much, but both Apache and Microsoft IIS handle
> such headers as expected and do not treat the request as a bad one as Nginx
> currently does.
>
> Best Regards
> M. Stavrev
>
> On Thu, Jan 23, 2020 at 9:29 PM Maxim Dounin <mdounin@mdounin.ru> wrote:
>
>> Hello!
>>
>> On Mon, Jan 20, 2020 at 05:29:25PM +0200, mstavrev@gmail.com wrote:
>>
>> > # HG changeset patch
>> > # User Marin Stavrev
>> > # Date 1579526641 -7200
>> > # Mon Jan 20 15:24:01 2020 +0200
>> > # Node ID bf238762fdaf03383c2f3c3718c401e6141e3935
>> > # Parent 6439ef81e37dfccfc3a8c57fed278bf56014ef39
>> > Fix for the HT on request headers problem (#1752)
>> >
>> > When client send HTTP request with a header of Content-Length that
>> starts with
>> > horizontal tab character (HT=0x09), Nginx responds with HTTP 400 Bad
>> Request.
>> > According to HTTP RFC2616 section 4.2, "... The field value MAY be
>> preceded by
>> > any amount of LWS, though a single SP is preferred.". The difinition of
>> LWS is:
>> >
>> > LWS = [CRLF] 1*( SP | HT )
>> >
>> > So a header such as the following should be processed fine:
>> >
>> > Content-Length:<0x09>110\r\n
>>
>> Note that RFC 2616 you are quoting was obsoleted by RFC 7230. In
>> particular, line folding (the "[CRLF]" part of the grammar) is
>> obsolete and must not be generated. Modern syntax rules to refer
>> to would be RFC 7230, section 3.2:
>>
>> header-field = field-name ":" OWS field-value OWS
>>
>> Where OWS is defined in section 3.2.3 as:
>>
>> OWS = *( SP / HTAB )
>> ; optional whitespace
>>
>> and text says that "a sender SHOULD generate the optional
>> whitespace as a single SP" where an optional whitespace can
>> improve readability.
>>
>> However, we haven't seen any interoperability problems due to no
>> HTAB support in nginx. As such, instead of adding HTAB support it
>> might be better to keep parsing strict.
>>
>> [...]
>>
>> --
>> Maxim Dounin
>> http://mdounin.ru/
>> _______________________________________________
>> nginx-devel mailing list
>> nginx-devel@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>>
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: nginx for Windows - WSASend() socket error 10057

$
0
0
So what is the meaning of Auth-Server and Auth-Port headers? So it's relevant only when nginx works as SMTP Proxy (not SMTP Server)? And these are host/port where to redirect SMTP requests?
Yeah, I was all the time surprised -- how come, it's set as Proxy but there is no setting where it redirects SMTP communication to. A little bit unexpected place for those setting.

Well, let me try...

I ran Fake SMTP Server on port 25.(I found on Internet some fake SMTP Server). I configured my test SMTP client to localhost:25 (later to 127.0.0.1:25). They send/receive successfully. So both SMTP Client and (fake) SMTP Server work fine.
127.0.0.1 works fine too.

I re-configured my test SMTP client to localhost:8025 (tried 127.0.0.1:8025 too). As well, I changed this section of config as follows:
http {
server {
listen 9000;

location /cgi-bin/nginxauth.cgi {
add_header Auth-Status OK;
add_header Auth-Server 127.0.0.1; # backend ip
add_header Auth-Port 25; # backend port
return 204;
}
}
}

The same error:
2020/02/14 17:37:18 [error] 15260#3328: *5 WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025

Update:
Detailed logging with debug information helped a lot.
This is what I noticed in there:

2020/02/14 17:40:28 [debug] 3940#22096: *1 smtp auth state
2020/02/14 17:40:28 [debug] 3940#22096: *1 WSARecv: fd:584 rc:0 24 of 4096
2020/02/14 17:40:28 [debug] 3940#22096: *1 smtp rcpt to:"RCPT TO:<ys@wmata.com>"
2020/02/14 17:40:28 [debug] 3940#22096: *1 event timer del: 584: 1172123084
2020/02/14 17:40:28 [debug] 3940#22096: *1 malloc: 02F8C260:2048
2020/02/14 17:40:28 [debug] 3940#22096: *1 stream socket 588
2020/02/14 17:40:28 [debug] 3940#22096: *1 connect to [::1]:9000, fd:588 #2
2020/02/14 17:40:28 [debug] 3940#22096: *1 select add event fd:588 ev:768
2020/02/14 17:40:28 [debug] 3940#22096: *1 select add event fd:588 ev:16
2020/02/14 17:40:28 [debug] 3940#22096: *1 event timer add: 588: 60000:1172123084
2020/02/14 17:40:28 [debug] 3940#22096: *1 event timer add: 588: 60000:1172123084

So it's trying to use IP6 rather than IP4.
And below:

2020/02/14 17:40:29 [debug] 3940#22096: *1 delete posted event 03171170
2020/02/14 17:40:29 [debug] 3940#22096: *1 mail auth http write handler
2020/02/14 17:40:29 [debug] 3940#22096: *1 WSASend: fd:588, -1, 0 of 306
2020/02/14 17:40:29 [error] 3940#22096: *1 WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
2020/02/14 17:40:29 [debug] 3940#22096: *1 event timer del: 588: 1172123084
2020/02/14 17:40:29 [debug] 3940#22096: *1 event timer del: 588: 1172123084

So, I replaced localhost with 127.0.0.1 like this:
auth_http 127.0.0.1:9000/cgi-bin/nginxauth.cgi;

And it worked. Since I forced it to use IP4.
Any idea how to use host name instead of IP address and still have it working?

Update 2:
I figured it out. Googled a little bit and ended up with the following change to my config:

http {
server {
listen 9000;
listen [::]:9000 ipv6only=on;

location /cgi-bin/nginxauth.cgi {
add_header Auth-Status OK;
add_header Auth-Server 127.0.0.1; # backend ip
add_header Auth-Port 25; # backend port
return 204;
}
}
}

Now it works.
But why just "listen 9000" doesn't listen on both IP4 and IP6?
Is it a bug?


Yury
________________________________
From: Sergey Brester <serg.brester@sebres.de>
Sent: Friday, February 14, 2020 5:59 AM
To: Yury Shpakov <yshpakov@hotmail.com>
Cc: nginx-devel@nginx.org <nginx-devel@nginx.org>
Subject: Re: nginx for Windows - WSASend() socket error 10057


I don't know what is wrong with your config... I guess your smtp server does not answer properly.

Is 127.0.0.2:143 really your SMTP-server?
Because port 143 is mostly an IMAP port - but you've specified protocol smtp in the server section.

Anyway I tested your config with my settings (replaced name and smtp-server, here 192.0.2.222:25) and enabled debug:

+ error_log logs/error-mail.log debug;
mail {
- server_name localhost;
+ server_name example.com;
....
http {
....
- add_header Auth-Server 127.0.0.2;
- add_header Auth-Port 143;
+ add_header Auth-Server 192.0.2.222;
+ add_header Auth-Port 25;

it works well - I see the test incoming mail (I send to myself via 8025 port) and following output in the log (a lot of irrelevant messages are removed):

>>>>>>>>>

2020/02/14 11:24:04 [debug] 121280#128244: *1 smtp mail from:"mail FROM:<test@example.com>"
....
2020/02/14 11:24:04 [debug] 121280#128244: *3 http request line: "GET /cgi-bin/nginxauth.cgi HTTP/1.0"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http uri: "/cgi-bin/nginxauth..cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http args: ""
2020/02/14 11:24:04 [debug] 121280#128244: *3 http exten: "cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http process request header line
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Host: localhost"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Method: none"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-User: "
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Pass: "
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Protocol: smtp"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-Login-Attempt: 1"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Client-IP: 127.0.0.1"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Client-Host: [UNAVAILABLE]"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-SMTP-Helo: myhost.example.com"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-SMTP-From: mail FROM:<test@example.com>"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header: "Auth-SMTP-To: rcpt TO:<test@example.com>"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http header done
2020/02/14 11:24:04 [debug] 121280#128244: *3 event timer del: 512: 1127939767
2020/02/14 11:24:04 [debug] 121280#128244: *3 generic phase: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 rewrite phase: 1
2020/02/14 11:24:04 [debug] 121280#128244: *3 search through nested static locations of ""
2020/02/14 11:24:04 [debug] 121280#128244: *3 test location: "/cgi-bin/nginxauth.cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 using configuration "/cgi-bin/nginxauth.cgi"
2020/02/14 11:24:04 [debug] 121280#128244: *3 http cl:-1 max:1048576
2020/02/14 11:24:04 [debug] 121280#128244: *3 rewrite phase: 3
2020/02/14 11:24:04 [debug] 121280#128244: *3 http set discard body
2020/02/14 11:24:04 [debug] 121280#128244: *3 HTTP/1.1 204 No Content
Server: nginx/1.17.4
Date: Fri, 14 Feb 2020 10:24:04 GMT
Connection: close
Auth-Status: OK
Auth-Server: 192.0.2.222
Auth-Port: 25

2020/02/14 11:24:04 [debug] 121280#128244: *3 write new buf t:1 f:0 008AD6A0, pos 008AD6A0, size: 164 file: 0, size: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter: l:1 f:0 s:164
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter limit 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 WSASend: fd:512, s:164
2020/02/14 11:24:04 [debug] 121280#128244: *3 http write filter 00000000
2020/02/14 11:24:04 [debug] 121280#128244: *3 http finalize request: 0, "/cgi-bin/nginxauth.cgi?" a:1, c:1
2020/02/14 11:24:04 [debug] 121280#128244: *3 http request count:1 blk:0
2020/02/14 11:24:04 [debug] 121280#128244: *3 http close request
2020/02/14 11:24:04 [debug] 121280#128244: *3 http log handler
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 008ACC50, unused: 1161
2020/02/14 11:24:04 [debug] 121280#128244: *3 close http connection: 512
2020/02/14 11:24:04 [debug] 121280#128244: *3 reusable connection: 0
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 008AC848
2020/02/14 11:24:04 [debug] 121280#128244: *3 free: 0039FDE0, unused: 28
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http read handler
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 164 of 1024
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http process status line
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http process headers
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Server: nginx/1.17.4"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Date: Fri, 14 Feb 2020 10:24:04 GMT"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Connection: close"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Auth-Status: OK"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Auth-Server: 192.0.2.222"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header: "Auth-Port: 25"
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail auth http header done
2020/02/14 11:24:04 [debug] 121280#128244: *1 event timer del: 496: 1127939764
2020/02/14 11:24:04 [debug] 121280#128244: *1 reusable connection: 0
2020/02/14 11:24:04 [debug] 121280#128244: *1 free: 008AC040, unused: 196
2020/02/14 11:24:04 [debug] 121280#128244: *1 stream socket 496
2020/02/14 11:24:04 [debug] 121280#128244: *1 connect to 192.0.2.222:25, fd:496 #4
2020/02/14 11:24:04 [debug] 121280#128244: *1 event timer add: 496: 60000:1127939769
2020/02/14 11:24:04 [debug] 121280#128244: *1 malloc: 008AC040:4096
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 post event 00897120
2020/02/14 11:24:04 [debug] 121280#128244: posted event 00897120
2020/02/14 11:24:04 [debug] 121280#128244: *1 delete posted event 00897120
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy dummy handler
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy smtp auth handler
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 22 of 4096
2020/02/14 11:24:04 [debug] 121280#128244: *1 mail proxy send ehlo
2020/02/14 11:24:04 [debug] 121280#128244: *1 malloc: 0039FDE0:256
2020/02/14 11:24:04 [debug] 121280#128244: *1 WSASend: fd:496, 0, 25 of 25
2020/02/14 11:24:04 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 196 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy send mail from
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 47 of 47
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 60 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy send rcpt to
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 45 of 45
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy smtp auth handler
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 63 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer add: 492: 86400000:1214280441
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer del: 496: 1127939769
2020/02/14 11:24:05 [info] 121280#128244: *1 client logged in, client: 127.0.0.1, server: 0.0.0.0:8025
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 1, #496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 63 of 63
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old: 1214280441, new: 1214280441
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 post event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 delete posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0, #492 > #496
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:492 rc:0 6 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 6 of 6
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old: 1214280441, new: 1214280441
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0, #496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 50 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 50 of 50
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 post event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 delete posted event 008830C8
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0, #492 > #496
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:492 rc:0 170 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:496, 0, 170 of 170
2020/02/14 11:24:05 [debug] 121280#128244: *1 event timer: 492, old: 1214280441, new: 1214280535
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
2020/02/14 11:24:05 [debug] 121280#128244: *1 mail proxy handler: 0, #496 > #492
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSARecv: fd:496 rc:0 56 of 4096
2020/02/14 11:24:05 [debug] 121280#128244: *1 WSASend: fd:492, 0, 56 of 56
2020/02/14 11:24:05 [debug] 121280#128244: worker cycle
....

<<<<<<<<<

Regards,
Sergey

13.02.2020 22:45, Yury Shpakov wrote:

Hi Sergey,


I reconfigured the config file as follows:

=== === ===
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


mail {
server_name localhost;
auth_http localhost:9000/cgi-bin/nginxauth.cgi;
# auth_http none;

smtp_auth none;
# smtp_auth login plain cram-md5;
# smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
xclient off;

server {
listen 8025;
protocol smtp;
proxy on;
proxy_pass_error_message on;
}
}

http {
server {
listen 9000;

location /cgi-bin/nginxauth.cgi {
add_header Auth-Status OK;
add_header Auth-Server 127.0.0.2; # backend ip
add_header Auth-Port 143; # backend port
return 204;
}
}
}
=== === ===

And now it's responding on port 9000 as expected:

=== === ===
C:\WINDOWS\system32>curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi
HTTP/1.1 204 No Content
Server: nginx/1.17.9
Date: Thu, 13 Feb 2020 21:30:54 GMT
Connection: keep-alive
Auth-Status: OK
Auth-Server: 127.0.0.2
Auth-Port: 143
=== === ===

However I'm still experiencing the same issue (in log file):

=== === ===
2020/02/13 16:29:24 [notice] 35048#26192: signal process started
2020/02/13 16:29:34 [error] 31732#22720: *1 WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
=== === ===

Tried under both admin and regular user.

Any further ideas how to get it fixed please?


Thank you,
Yury

________________________________
From: Sergey Brester <serg.brester@sebres.de>
Sent: Wednesday, February 12, 2020 1:51 PM
To: Yury Shpakov <yshpakov@hotmail.com>
Cc: nginx-devel@nginx.org <nginx-devel@nginx.org>
Subject: Re: nginx for Windows - WSASend() socket error 10057


I answered inline...

12.02.2020 18:59, Yury Shpakov wrote:

Hi Sergey,


Thank you for you response.

I tried netstat /nabo and I don't see any reference to port 9000 at all.
So a problem is to make nginx to listen on port 9000 (as server)?
Or nginx is not listening on port 9000 but rather sending requests to port 9000 (as client)?
With setting of `auth_http`, you are defining an URL to the service responsible for authentication (and upstream choice).
Of course then you should have something that would response to the auth-requests (your own upstream, or some nginx location, or some "foreign" http-server).

See https://docs.nginx.com/nginx/admin-guide/mail-proxy/mail-proxy/ for more examples.
Maybe it's easier not to use auth_http at all? I was trying to remove it from configuration file but nginx was not happy.

I have my own auth-module so I don't know how it can be solved in stock-nginx without this directive.

Take a look here - https://serverfault.com/questions/594962/nginx-understanding-the-purpose-of-auth-http-imap-proxy - you can use some nginx location (and internal URL to same nginx instance) to specify that.

Anyway it is recommended to use some auth (on nginx side), because it'd preserve the resources of mail-servers, allow you to authenticate email clients with same user/password for all mail-servers (smtp, imap, pop3, etc) as well as the same user/pwd as for some other http-services. And it is used to choose an upstream server (if multiple) for the email processing.

At this point I don't need any authentication. I was told by my boss to use nginx for load testing of our service sending emails (SMTP client). I've got some SMTP Server and nginx would be used as SMTP proxy because it allows to set up delays.
Well, an auth request to some nginx-location would allow you to set up delays even on authentication phase.
And take into account that I REMOVED "--with-http_ssl_module" from parameters when I was building nginx.

And you advised to download some nginx.exe files but I believe they were built without "--with-mail" parameter (which I need).
Although, it was compiled with "--with-mail" (you can see all parameters in provided GH-linkhttps://github.com/sebres/nginx/releases/tag/release-1.13..0)
But it would not help, because basically your issue seems to be the configuration (not the nginx.exe).

Thank you,
Yury

________________________________
From: Sergey Brester <serg.brester@sebres.de>
Sent: Wednesday, February 12, 2020 7:38 AM
To: nginx-devel@nginx.org <nginx-devel@nginx.org>
Cc: Yury Shpakov <yshpakov@hotmail.com>
Subject: Re: nginx for Windows - WSASend() socket error 10057

It looks like your service defined in auth_http doesn't answer (or no listener on 127.0.0.1 port 9000?)...

try netstat (in cmd as admin):

netstat /nabo
netstat /nabo | grep -A 1 ":9000\b"

and check whether the listener on port 9000 is bound to 127.0.0.1 (or it is 0.0.0.0 only?) and it is the process you expect to see there (can be "reserved" by some other windows-service).

additionally try to telnet or curl it:

curl -H "Auth-Method: plain" -H "Auth-User: user" -H "Auth-Pass: pwd" -H "Auth-Protocol: imap" -H "Auth-Login-Attempt: 1" -i http://127.0.0.1:9000/cgi-bin/nginxauth.cgi

if it does not answer, make another attempt by replace 127.0.0.1 with 0.0.0..0 (or a host-name).

If it answers - see whether it is the expected response (some examples of good and bad responses are described in http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html).

But I guess if WSASend fails, it would probably (unexpected) reject the connection during the send (or even connect) process.
It can be also invalid (unexpected) content-length in keep-alive connect to auth-upstream - so send but still receive is expected (or vice versa).

Also follow this forum topic addressing similar issue: https://forum.nginx.org/read.php?2,257206,257207#msg-257207

Anyway it doesn't look to me like an issue of nginx (regardless windows or not), but you can also try some other ready build (for example on my GHhttps://github.com/sebres/nginx/releases/tag/release-1.13.0 - nginx.ziphttps://github.com/sebres/nginx/files/2246440/nginx.zip, where it works well).

Regards,
Sergey

12.02.2020 03:01, Yury Shpakov wrote:

Hi there,
Trying to make nginx work as SMTP server and/or SMTP proxy. Done everything according to:
http://nginx.org/en/docs/howto_build_on_win32.html
But excluded (don't care about SSL at this point so don't want to install/configure Perl now):
--with-openssl=objs/lib/openssl-master \
--with-openssl-opt=no-asm \
--with-http_ssl_module \
And added:
--with-mail
nmake was successful and nginx.exe was created.
However nginx.exe keeps failing with the error:
WSASend() failed (10057: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied) while in http auth state, client: 127.0.0.1, server: 0.0.0.0:8025
Windows API says the following about this error:

WSAENOTCONN
10057

Socket is not connected.
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendtohttps://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-sendto) no address was supplied. Any other type of operation might also return this error—for example, setsockopthttps://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-setsockopt setting SO_KEEPALIVEhttps://docs.microsoft.com/en-us/windows/desktop/winsock/so-keepalive if the connection has been reset.
https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
Windows Sockets Error Codes (Winsock2.h) - Win32 apps | Microsoft Docshttps://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
Return code/value Description; WSA_INVALID_HANDLE 6: Specified event object handle is invalid. An application attempts to use an event object, but the specified handle is not valid.
docs.microsoft.com
Managed to debug your code in VS 2010 a little bit but it's brutal C so it's hard to figure your code out. And this debugger doesn't show you any local variables values.
Any recommendation for me to make it work?
Tried to play with config (commenting/uncommenting):
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
mail {
server_name localhost;
auth_http localhost:9000/cgi-bin/nginxauth.cgi;
# auth_http none;
smtp_auth none;
# smtp_auth login plain cram-md5;
# smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
xclient off;
server {
listen 8025;
protocol smtp;
proxy on;
proxy_pass_error_message on;
}
}
Tried both under a regular user and under admin. Tried on 25, 1025 and 8025 ports.
Thank you,
Yury


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org<mailto:nginx-devel@nginx.org>http://mailman.nginx.org/mailman/listinfo/nginx-devel
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Building a Let's Encrypt module

$
0
0
Hello nginx-devel.

I'm a developer on Certbot, EFF's Let's Encrypt client. I've been
working on Certbot's NGINX plugin for a few years now. This is an
extension of the standalone Certbot program that operates on a user's
behalf to modify their configuration files to retrieve and install SSL
certificates.

For the obvious reasons, this approach has its drawbacks. For a while
now, the Certbot team has been dreaming of a way to get certs
automatically as part of the server, without a standalone application
needed (similar to what Caddy does).

From our research, it seems like the best approach would be to write an
NGINX module. I've found some information about what this would entail
and the best ways to go about doing so, but I still have some open
questions. This is where you all come in. I would love any thoughts,
feedback, proposed solutions, clarifications, pointing out of
fundamental errors in understanding for the following:

Basically our thinking so far is to write a plugin that will fetch and
load certificates behind the scenes. Ideally it would do this decoupled
from incoming requests. The problem we've been running into is about
permissions and available actions -- we haven't found a clean way to
either run scheduled tasks (can't modify cron from inside a module) or
reload NGINX configurations from inside a plugin in vanilla open source
NGINX. Are there ways to do this that we just haven't found? And if not,
is there any chance of getting someone from the NGINX team to work with
us to make that possible?

If those are possible, we'd also have to decide if it's best to include
an ACME library within the plugin itself, or shell out to certbot to
fetch and/or manage certificates. Is calling out to an external process
from inside an NGINX plugin possible?

If we do get all of this working, we'd want to have the easiest possible
solution for users to install the plugin. Obviously the easiest way
would be for it to be built into NGINX itself :) Barring that, we could
probably find some way to package and distribute it. We're currently in
the process of moving our distribution to Snaps, so once we get that
infrastructure set up there'll be the option of repackaging NGINX with
the plugin included and distributing the whole thing.

The other thing we were considering was to build on top of OpenResty
instead, which seems to have a bit more functionality available.
Obviously that isn't ideal, but if it's the only way forward we might
start looking into performance and distribution options for that.

Looking forward to hearing thoughts.

Best,

Erica Portnoy
Senior Staff Technologist
Electronic Frontier Foundation

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

This site can’t be reached: what aspects, elements, configurations, do I have to check and verify?

$
0
0
Hi all,
just the day after getting everything fine: https://forum.nginx.org/read.php?2,286991,287001#msg-287001, during installation of another software in the PC I got problems with grub system in Ubuntu 18.04.4 Desktop, which I resolved copying, from an installation iso image, the /bin/bash folder: https://askubuntu.com/questions/1210267/missing-operating-system-error-unknown-filesystem-grub-rescue

But to my surprise, now I'm not able to see my webpage anymore, even if, apparently, everything seems ok.
"
This site can’t be reached https://ggc.world/ is unreachable.
ERR_ADDRESS_UNREACHABLE " :

https://drive.google.com/open?id=1NYLyXP5zpFN5_9TkWspY6FymaMauKUGv

And this is remarked with the digicert's and check-your-website-server's checks:
- https://drive.google.com/open?id=1EeOYkWzHXaMmOJKBnBbPYS-F9fcyPFXM
- https://drive.google.com/open?id=1DzuQlm6wkWvH7_-yfRowM45sAm2FKMWa


But apparently seems everything ok:


(base) marco@pc01:~/webMatters/vueMatters/testproject$ npm run serve

> testproject@0.1.0 serve /home/marco/webMatters/vueMatters/testproject
> vue-cli-service serve

INFO Starting development server...
98% after emitting CopyPlugin

DONE Compiled successfully in 906ms 9:36:31 AM


App running at:
- Local: http://localhost:8080
- Network: http://ggc.world/

Note that the development build is not optimized.
To create a production build, run npm run build.



(base) marco@pc01:~$ sudo nano /etc/nginx/nginx.conf
[sudo] password for marco:


user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

# Basic Settings

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# SSL Settings

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;

include /etc/nginx/conf.d/*.conf;
}


sudo nano /etc/nginx/conf.d/default.conf :

server {
listen 443 ssl http2 default_server;
server_name ggc.world;

ssl_certificate /etc/letsencrypt/live/ggc.world/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ggc.world/privkey.pem; # managed by Certbot

ssl_trusted_certificate /etc/letsencrypt/live/ggc.world/chain.pem;

ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



ssl_session_timeout 5m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
#ssl_stapling on;
#ssl_stapling_verify on;

access_log /var/log/nginx/ggcworld-access.log combined;

add_header Strict-Transport-Security "max-age=31536000";
location = /favicon.ico { access_log off; log_not_found off; }

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#proxy_set_header Host $host;
}
}

server {
listen 80 default_server;
listen [::]:80 default_server;
error_page 497 https://$host:$server_port$request_uri;
server_name www.ggc.world;
return 301 https://$server_name$request_uri;

access_log /var/log/nginx/ggcworld-access.log combined;

add_header Strict-Transport-Security "max-age=31536000";
location = /favicon.ico { access_log off; log_not_found off; }

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#proxy_set_header Host $host;
}
}

upstream websocket {
ip_hash;
server localhost:3000;
}

server {
listen 81;
server_name ggc.world www.ggc.world;

#location / {
location ~ ^/(websocket|websocket\/socket-io) {
proxy_pass http://127.0.0.1:4201;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwared-For $remote_addr;
proxy_set_header Host $host;

proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
}

(base) marco@pc01:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-02-17 07:52:51 CET; 1h 58min ago
Docs: man:nginx(8)
Process: 8830 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 1090 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1067 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1092 (nginx)
Tasks: 9 (limit: 4915)
CGroup: /system.slice/nginx.service
├─1092 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─8831 nginx: worker process
├─8832 nginx: worker process
├─8833 nginx: worker process
├─8835 nginx: worker process
├─8836 nginx: worker process
├─8837 nginx: worker process
├─8838 nginx: worker process
└─8840 nginx: worker process

feb 17 07:52:51 pc01 systemd[1]: Starting A high performance web server and a reverse proxy server...
feb 17 07:52:51 pc01 systemd[1]: Started A high performance web server and a reverse proxy server.
feb 17 09:51:29 pc01 systemd[1]: Reloading A high performance web server and a reverse proxy server.
feb 17 09:51:29 pc01 systemd[1]: Reloaded A high performance web server and a reverse proxy server.
(base) marco@pc01:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


Before trying to access the website, I cleaned all the content of the web-browser's cache and history.
The only Google Chrome's extension installed is Vue.js devtools

The DNS provider configuration matches with the Internet Service Provider configuration:
- https://drive.google.com/open?id=1YHhRqMcyHj0wSRVjjtQXOjrO-Zj1wlbz
- https://drive.google.com/open?id=1vk9YEwl_PW4uifFMAo9m5nnkzEFewM7I

The internet connection is working fine.

What aspects, elements, configurations, do I have to check and verify?
How could I solve this problem?
Looking forward to your kind help.
Marco

NGINX Mailproxy

$
0
0
Hello

I am trying to use nginx as reverse-mailproxy for multiple mailservers.Whenever I have a client which connects to the nginx-mailproxy via STARTLS or SSL, the NGINX passes a malformed LOGIN packets to the backend mailserver, per example:
(nginx = nginx, mails = backend mailserver, in the first case MailEnable, in the second case Dovecot)

nginx>5 LOGIN {18}
mails>+ go ahead
nginx>user@domain.tld {8}
mails>+ go ahead
nginx>PASSWORD
mails>BAD UNKNOWN Command

nginx>3 LOGIN {17}
mails> + OK
nginx> user@domain.tld {8}
mails> + OK
nginx>PASSWORD
mails>3 NO [AUTHENTICATIONFAILED] Authentication failed.


As you can see, nginx adds a suffix to the username, which lets the backendserver fail. Wireshark displays this additional data as {number}, I can also provide the hex variant of the packets.
NGINX also adds this suffix, if the username is passed via NGX auth header.
I've tested this with the nginx-full binary from the ubuntu repositories, as well as a self-compiled binary.

Used configuration:


  server_name server.domain.tld;
  auth_http url;
  proxy on;
  proxy_pass_error_message on;
  imap_capabilities "IMAP4rev1" "UIDPLUS" "IDLE" "LITERAL +" "QUOTA" "SASL-IR" "ID" "ENABLE";
  pop3_auth plain apop;
  pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL";
  smtp_capabilities "SIZE 31457280" ENHANCEDSTATUSCODES 8BITMIME DSN;
  ssl_certificate /path/to/cert.crt;
  ssl_certificate_key /path/to/privkey.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  ssl_prefer_server_ciphers on;
  error_log /var/log/nginx/mailerror.log info;
  xclient on;

#                       POP3                            #
  server {
    listen 143;
    protocol imap;
    starttls on;
    imap_auth plain login;
    auth_http_header X-Auth-Port 143;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }
  server {
    protocol pop3;
    listen 110;
    starttls on;
    pop3_auth plain;
    proxy on;
    auth_http_header X-Auth-Port 110;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }

#                       IMAP                            #

  server {
    listen 993;
    ssl on;
    protocol imap;
    imap_auth plain login;
    auth_http_header X-Auth-Port 993;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }
  server {
    protocol pop3;
    listen 995;
    ssl on;
    pop3_auth plain;
    auth_http_header X-Auth-Port 995;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }

#                       SMTP                            #

server {
    listen    25;
    xclient off;
    protocol  smtp;
    starttls on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 25;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
    auth_http_header X-Real-IP $remote_addr;
}
server {
    listen    587;
    xclient off;
    protocol  smtp;
    starttls on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 587;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";

}
server {
    listen    465;
    xclient off;
    protocol  smtp;
    ssl on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 465;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";


}
Is this a configuration-related issue? How can I fix this?
Thank you very much!

Fabian
Hello

I am trying to use nginx as reverse-mailproxy for multiple mailservers.
Whenever I have a client which connects to the nginx-mailproxy via STARTLS or SSL, the NGINX passes a malformed LOGIN packets to the backend mailserver, per example:
(nginx = nginx, mails = backend mailserver, in the first case MailEnable, in the second case Dovecot)

nginx>5 LOGIN {18}
mails>+ go ahead
nginx>user@domain.tld {8}
mails>+ go ahead
nginx>PASSWORD
mails>BAD UNKNOWN Command

nginx>3 LOGIN {17}
mails> + OK
nginx> user@domain.tld {8}
mails> + OK
nginx>PASSWORD
mails>3 NO [AUTHENTICATIONFAILED] Authentication failed.


As you can see, nginx adds a suffix to the username, which lets the backendserver fail. Wireshark displays this additional data as {number}, I can also provide the hex variant of the packets.
NGINX also adds this suffix, if the username is passed via NGX auth header.
I've tested this with the nginx-full binary from the ubuntu repositories, as well as a self-compiled binary.

Used configuration:


  server_name server.domain.tld;
  auth_http url;
  proxy on;
  proxy_pass_error_message on;
  imap_capabilities "IMAP4rev1" "UIDPLUS" "IDLE" "LITERAL +" "QUOTA" "SASL-IR" "ID" "ENABLE";
  pop3_auth plain apop;
  pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL";
  smtp_capabilities "SIZE 31457280" ENHANCEDSTATUSCODES 8BITMIME DSN;
  ssl_certificate /path/to/cert.crt;
  ssl_certificate_key /path/to/privkey.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  ssl_prefer_server_ciphers on;
  error_log /var/log/nginx/mailerror.log info;
  xclient on;

#                       POP3                            #
  server {
    listen 143;
    protocol imap;
    starttls on;
    imap_auth plain login;
    auth_http_header X-Auth-Port 143;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }
  server {
    protocol pop3;
    listen 110;
    starttls on;
    pop3_auth plain;
    proxy on;
    auth_http_header X-Auth-Port 110;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }

#                       IMAP                            #

  server {
    listen 993;
    ssl on;
    protocol imap;
    imap_auth plain login;
    auth_http_header X-Auth-Port 993;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }
  server {
    protocol pop3;
    listen 995;
    ssl on;
    pop3_auth plain;
    auth_http_header X-Auth-Port 995;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
  }

#                       SMTP                            #

server {
    listen    25;
    xclient off;
    protocol  smtp;
    starttls on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 25;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";
    auth_http_header X-Real-IP $remote_addr;
}
server {
    listen    587;
    xclient off;
    protocol  smtp;
    starttls on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 587;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";

}
server {
    listen    465;
    xclient off;
    protocol  smtp;
    ssl on;
    smtp_auth login plain cram-md5;
    auth_http_header X-Auth-Port 465;
    auth_http_header User-Agent "Nginx POP3/IMAP4 proxy";


}
Is this a configuration-related issue? How can I fix this?
Thank you very much!

Fabian
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: This site can’t be reached: what aspects, elements, configurations, do I have to check and verify?

$
0
0
Big Update:SOLVED (but still do not know why)...

I fixed the PC's IP Address, and everything went fine.... But I do not actually understand why everything went fine, if, before the problem with the software installation, the local ip address was dynamic and it was already working fine.

[njs] Introduced ToLength() according to ES6.

$
0
0
details: https://hg.nginx.org/njs/rev/13dbdff9b76f
branches:
changeset: 1326:13dbdff9b76f
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Feb 17 16:13:43 2020 +0300
description:
Introduced ToLength() according to ES6.

Since ES6, according to the spec maximum length value is 2**53 - 1 not
2**32 - 1, so uint64_t data type is required.

diffstat:

src/njs_array.c | 418 +++++++++++++++++++++++---------------------
src/njs_array.h | 4 +-
src/njs_chb.h | 8 +-
src/njs_function.c | 8 +-
src/njs_json.c | 10 +-
src/njs_number.c | 24 ++
src/njs_number.h | 14 +-
src/njs_object.c | 2 +-
src/njs_object.h | 4 +-
src/njs_regexp.c | 4 +-
src/njs_string.c | 5 +-
src/njs_typed_array.c | 24 +-
src/njs_value.c | 18 +-
src/njs_value.h | 63 ++++++-
src/njs_value_conversion.h | 2 +-
src/test/njs_unit_test.c | 126 ++++++++++++-
16 files changed, 475 insertions(+), 259 deletions(-)

diffs (truncated from 1794 to 1000 lines):

diff -r 974e6c195410 -r 13dbdff9b76f src/njs_array.c
--- a/src/njs_array.c Thu Feb 13 16:25:37 2020 +0300
+++ b/src/njs_array.c Mon Feb 17 16:13:43 2020 +0300
@@ -18,13 +18,13 @@ typedef struct {

njs_array_t *array;

- uint32_t from;
- uint32_t to;
+ int64_t from;
+ int64_t to;
} njs_array_iterator_args_t;


typedef njs_int_t (*njs_array_iterator_handler_t)(njs_vm_t *vm,
- njs_array_iterator_args_t *args, njs_value_t *entry, uint32_t n);
+ njs_array_iterator_args_t *args, njs_value_t *entry, uint64_t n);


static njs_int_t njs_array_prototype_slice_copy(njs_vm_t *vm,
@@ -128,9 +128,8 @@ njs_array_convert_to_slow_array(njs_vm_t
length = array->length;

for (i = 0; i < length; i++) {
- njs_uint32_to_string(&index, i);
-
if (njs_is_valid(&array->start[i])) {
+ njs_uint32_to_string(&index, i);
prop = njs_object_property_add(vm, &value, &index, 0);
if (njs_slow_path(prop == NULL)) {
return NJS_ERROR;
@@ -183,7 +182,8 @@ njs_array_length_set(njs_vm_t *vm, njs_v
njs_object_prop_t *prev, njs_value_t *setval)
{
double num, idx;
- uint32_t i, length, prev_length;
+ uint32_t i, length;
+ uint64_t prev_length;
njs_int_t ret;
njs_array_t *array, *keys;

@@ -197,7 +197,7 @@ njs_array_length_set(njs_vm_t *vm, njs_v
return ret;
}

- length = njs_number_to_length(num);
+ length = (uint32_t) njs_number_to_length(num);
if ((double) length != num) {
njs_range_error(vm, "Invalid array length");
return NJS_ERROR;
@@ -306,7 +306,7 @@ njs_array_expand(njs_vm_t *vm, njs_array
size += size / 2;
}

- if (njs_slow_path(size > NJS_ARRAY_MAX_LENGTH)) {
+ if (njs_slow_path(size > (UINT32_MAX / sizeof(njs_value_t)))) {
goto memory_error;
}

@@ -354,7 +354,7 @@ njs_array_constructor(njs_vm_t *vm, njs_

if (size == 1 && njs_is_number(&args[0])) {
num = njs_number(&args[0]);
- size = (uint32_t) num;
+ size = (uint32_t) njs_number_to_length(num);

if ((double) size != num) {
njs_range_error(vm, "Invalid array length");
@@ -529,7 +529,7 @@ njs_array_length(njs_vm_t *vm,njs_object
return ret;
}

- length = njs_number_to_length(num);
+ length = (uint32_t) njs_number_to_length(num);
if ((double) length != num) {
njs_range_error(vm, "Invalid array length");
return NJS_ERROR;
@@ -582,7 +582,7 @@ njs_array_prototype_slice(njs_vm_t *vm,
njs_index_t unused)
{
int64_t start, end, length;
- uint32_t object_length;
+ uint64_t object_length;
njs_int_t ret;
njs_value_t *this;

@@ -658,7 +658,7 @@ njs_array_prototype_slice_copy(njs_vm_t
uint32_t n;
njs_int_t ret;
njs_array_t *array, *keys;
- njs_value_t *value, index, retval, array_value;
+ njs_value_t *value, retval, self;
const u_char *src, *end;
njs_slice_prop_t string_slice;
njs_string_prop_t string;
@@ -688,10 +688,8 @@ njs_array_prototype_slice_copy(njs_vm_t

/* src value may be in Array.prototype object. */

- njs_uint32_to_string(&index, start++);
-
value = &array->start[n++];
- ret = njs_value_property(vm, this, &index, value);
+ ret = njs_value_property_i64(vm, this, start++, value);
if (njs_slow_path(ret == NJS_ERROR)) {
return NJS_ERROR;
}
@@ -746,10 +744,8 @@ njs_array_prototype_slice_copy(njs_vm_t
} else if (njs_is_object(this)) {

do {
- njs_uint32_to_string(&index, start++);
-
value = &array->start[n++];
- ret = njs_value_property(vm, this, &index, value);
+ ret = njs_value_property_i64(vm, this, start++, value);

if (ret != NJS_OK) {
njs_set_invalid(value);
@@ -774,19 +770,17 @@ njs_array_prototype_slice_copy(njs_vm_t
goto done;
}

- njs_set_array(&array_value, array);
+ njs_set_array(&self, array);

if (njs_fast_object(length)) {
do {
- njs_uint32_to_string(&index, start++);
-
- ret = njs_value_property(vm, this, &index, &retval);
+ ret = njs_value_property_i64(vm, this, start++, &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return NJS_ERROR;
}

if (ret == NJS_OK) {
- ret = njs_value_property_set(vm, &array_value, &index, &retval);
+ ret = njs_value_property_i64_set(vm, &self, start, &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -810,8 +804,7 @@ njs_array_prototype_slice_copy(njs_vm_t
goto done;
}

- ret = njs_value_property_set(vm, &array_value, &keys->start[n],
- &retval);
+ ret = njs_value_property_set(vm, &self, &keys->start[n], &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
goto done;
}
@@ -835,11 +828,11 @@ static njs_int_t
njs_array_prototype_push(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_uint_t i;
njs_array_t *array;
- njs_value_t *this, index;
+ njs_value_t *this;

length = 0;
this = njs_argument(args, 0);
@@ -874,10 +867,13 @@ njs_array_prototype_push(njs_vm_t *vm, n
return ret;
}

+ if (njs_slow_path((length + nargs - 1) > NJS_MAX_LENGTH)) {
+ njs_type_error(vm, "Invalid length");
+ return NJS_ERROR;
+ }
+
for (i = 1; i < nargs; i++) {
- njs_uint32_to_string(&index, length++);
-
- ret = njs_value_property_set(vm, this, &index, &args[i]);
+ ret = njs_value_property_i64_set(vm, this, length++, &args[i]);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -898,10 +894,10 @@ static njs_int_t
njs_array_prototype_pop(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_array_t *array;
- njs_value_t *this, *entry, index;
+ njs_value_t *this, *entry;

this = njs_argument(args, 0);

@@ -921,6 +917,15 @@ njs_array_prototype_pop(njs_vm_t *vm, nj

if (njs_is_valid(entry)) {
vm->retval = *entry;
+
+ } else {
+ /* src value may be in Array.prototype object. */
+
+ ret = njs_value_property_i64(vm, this, array->length,
+ &vm->retval);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return NJS_ERROR;
+ }
}
}

@@ -932,15 +937,23 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
return ret;
}

- if (length != 0) {
- njs_uint32_to_string(&index, --length);
-
- ret = njs_value_property_delete(vm, this, &index, &vm->retval);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return ret;
- }
+ if (length == 0) {
+ njs_set_undefined(&vm->retval);
+ goto done;
}

+ ret = njs_value_property_i64(vm, this, --length, &vm->retval);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
+ ret = njs_value_property_i64_delete(vm, this, length, NULL);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
+done:
+
ret = njs_object_length_set(vm, this, length);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
@@ -955,11 +968,11 @@ njs_array_prototype_unshift(njs_vm_t *vm
njs_index_t unused)
{
double idx;
- uint32_t from, to, length;
+ uint64_t from, to, length;
njs_int_t ret;
njs_uint_t n;
njs_array_t *array, *keys;
- njs_value_t *this, entry, index;
+ njs_value_t *this, entry;

this = njs_argument(args, 0);
length = 0;
@@ -970,14 +983,9 @@ njs_array_prototype_unshift(njs_vm_t *vm
return ret;
}

- if (njs_is_fast_array(this)) {
+ if (njs_fast_path(njs_is_fast_array(this))) {
array = njs_array(this);

- if (array->length > (UINT32_MAX - n)) {
- njs_type_error(vm, "Invalid length");
- return NJS_ERROR;
- }
-
if (n != 0) {
ret = njs_array_expand(vm, array, n, 0);
if (njs_slow_path(ret != NJS_OK)) {
@@ -1009,7 +1017,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
goto done;
}

- if (length > (UINT32_MAX - n)) {
+ if (njs_slow_path((length + n) > NJS_MAX_LENGTH)) {
njs_type_error(vm, "Invalid length");
return NJS_ERROR;
}
@@ -1031,11 +1039,9 @@ njs_array_prototype_unshift(njs_vm_t *vm
}

if (ret == NJS_OK) {
- idx = njs_string_to_index(&keys->start[from]);
-
- njs_uint32_to_string(&index, (uint32_t) idx + nargs - 1);
-
- ret = njs_value_property_set(vm, this, &index, &entry);
+ idx = njs_string_to_index(&keys->start[from]) + n;
+
+ ret = njs_value_property_i64_set(vm, this, idx, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
njs_array_destroy(vm, keys);
return ret;
@@ -1045,7 +1051,7 @@ njs_array_prototype_unshift(njs_vm_t *vm

njs_array_destroy(vm, keys);

- length += nargs - 1;
+ length += n;

goto copy;
}
@@ -1055,9 +1061,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
to = length;

while (from > 0) {
- njs_uint32_to_string(&index, --from);
-
- ret = njs_value_property_delete(vm, this, &index, &entry);
+ ret = njs_value_property_i64_delete(vm, this, --from, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -1065,9 +1069,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
to--;

if (ret == NJS_OK) {
- njs_uint32_to_string(&index, to);
-
- ret = njs_value_property_set(vm, this, &index, &entry);
+ ret = njs_value_property_i64_set(vm, this, to, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -1077,9 +1079,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
copy:

for (n = 1; n < nargs; n++) {
- njs_uint32_to_string(&index, n - 1);
-
- ret = njs_value_property_set(vm, this, &index, &args[n]);
+ ret = njs_value_property_i64_set(vm, this, n - 1, &args[n]);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -1102,10 +1102,10 @@ static njs_int_t
njs_array_prototype_shift(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- uint32_t i, length;
+ uint64_t i, length;
njs_int_t ret;
njs_array_t *array;
- njs_value_t *this, *item, entry, index;
+ njs_value_t *this, *item, entry;

this = njs_argument(args, 0);
length = 0;
@@ -1122,13 +1122,21 @@ njs_array_prototype_shift(njs_vm_t *vm,

if (array->length != 0) {
array->length--;
-
item = &array->start[0];
- array->start++;

if (njs_is_valid(item)) {
vm->retval = *item;
+
+ } else {
+ /* src value may be in Array.prototype object. */
+
+ ret = njs_value_property_i64(vm, this, 0, &vm->retval);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return NJS_ERROR;
+ }
}
+
+ array->start++;
}

return NJS_OK;
@@ -1143,25 +1151,19 @@ njs_array_prototype_shift(njs_vm_t *vm,
goto done;
}

- njs_uint32_to_string(&index, 0);
-
- ret = njs_value_property_delete(vm, this, &index, &vm->retval);
+ ret = njs_value_property_i64_delete(vm, this, 0, &vm->retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}

for (i = 1; i < length; i++) {
- njs_uint32_to_string(&index, i);
-
- ret = njs_value_property_delete(vm, this, &index, &entry);
+ ret = njs_value_property_i64_delete(vm, this, i, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}

if (ret == NJS_OK) {
- njs_uint32_to_string(&index, i - 1);
-
- ret = njs_value_property_set(vm, this, &index, &entry);
+ ret = njs_value_property_i64_set(vm, this, i - 1, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -1304,7 +1306,7 @@ static njs_int_t
njs_array_prototype_reverse(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_uint_t i, n;
njs_value_t value, *this;
@@ -1385,15 +1387,13 @@ njs_array_prototype_join(njs_vm_t *vm, n
njs_index_t unused)
{
u_char *p, *last;
- size_t size;
- ssize_t length;
- uint32_t len;
+ int64_t length;
+ uint64_t i, len, size;
njs_int_t ret;
njs_chb_t chain;
njs_utf8_t utf8;
- njs_uint_t i;
njs_array_t *array;
- njs_value_t *value, *this, index, entry;
+ njs_value_t *value, *this, entry;
njs_string_prop_t separator, string;

this = njs_argument(args, 0);
@@ -1447,13 +1447,13 @@ njs_array_prototype_join(njs_vm_t *vm, n
njs_chb_init(&chain, vm->mem_pool);

for (i = 0; i < len; i++) {
- if (njs_fast_path(array != NULL)) {
+ if (njs_fast_path(njs_object(this)->fast_array
+ && njs_is_valid(&array->start[i])))
+ {
value = &array->start[i];

} else {
- njs_uint32_to_string(&index, i);
-
- ret = njs_value_property(vm, this, &index, &entry);
+ ret = njs_value_property_i64(vm, this, i, &entry);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -1493,6 +1493,11 @@ njs_array_prototype_join(njs_vm_t *vm, n

length += separator.length;
njs_chb_append(&chain, separator.start, separator.size);
+
+ if (njs_slow_path(length > NJS_STRING_MAX_LENGTH)) {
+ njs_range_error(vm, "invalid string length");
+ return NJS_ERROR;
+ }
}

njs_chb_drop(&chain, separator.size);
@@ -1597,14 +1602,22 @@ njs_array_indices(njs_vm_t *vm, const nj

njs_inline njs_int_t
njs_array_object_handler(njs_vm_t *vm, njs_array_iterator_handler_t handler,
- njs_array_iterator_args_t *args, njs_value_t *key, uint32_t i)
+ njs_array_iterator_args_t *args, njs_value_t *key, uint64_t i)
{
njs_int_t ret;
njs_value_t prop, *entry;

- ret = njs_value_property(vm, args->value, key, &prop);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return ret;
+ if (key != NULL) {
+ ret = njs_value_property(vm, args->value, key, &prop);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
+ } else {
+ ret = njs_value_property_i64(vm, args->value, i, &prop);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
}

entry = (ret == NJS_OK) ? &prop : njs_value_arg(&njs_value_invalid);
@@ -1627,10 +1640,10 @@ njs_array_iterator(njs_vm_t *vm, njs_arr
njs_array_iterator_handler_t handler)
{
double idx;
- uint32_t length, i, from, to;
+ uint64_t length, i, from, to;
njs_int_t ret;
- njs_array_t *keys;
- njs_value_t *value, character, index, string_obj;
+ njs_array_t *array, *keys;
+ njs_value_t *value, *entry, prop, character, string_obj;
njs_object_t *object;
const u_char *p, *end, *pos;
njs_string_prop_t string_prop;
@@ -1640,16 +1653,30 @@ njs_array_iterator(njs_vm_t *vm, njs_arr
to = args->to;

if (njs_is_array(value)) {
- if (njs_slow_path(!njs_is_fast_array(value))) {
- goto process_object;
- }
-
- for (i = from; i < to; i++) {
- if (i < njs_array_len(value)) {
- ret = handler(vm, args, &njs_array_start(value)[i], i);
+ array = njs_array(value);
+
+ for (; from < to; from++) {
+ if (njs_slow_path(!array->object.fast_array)) {
+ goto process_object;
+ }
+
+ if (njs_fast_path(from < array->length
+ && njs_is_valid(&array->start[from])))
+ {
+ ret = handler(vm, args, &array->start[from], from);

} else {
- ret = handler(vm, args, njs_value_arg(&njs_value_invalid), i);
+ entry = njs_value_arg(&njs_value_invalid);
+ ret = njs_value_property_i64(vm, value, from, &prop);
+ if (njs_slow_path(ret != NJS_DECLINED)) {
+ if (ret == NJS_ERROR) {
+ return NJS_ERROR;
+ }
+
+ entry = &prop;
+ }
+
+ ret = handler(vm, args, entry, from);
}

if (njs_slow_path(ret != NJS_OK)) {
@@ -1680,7 +1707,7 @@ njs_array_iterator(njs_vm_t *vm, njs_arr
value = njs_object_value(value);
}

- length = (uint32_t) njs_string_prop(&string_prop, value);
+ length = njs_string_prop(&string_prop, value);

p = string_prop.start;
end = p + string_prop.size;
@@ -1760,9 +1787,7 @@ process_object:
}

for (i = from; i < to; i++) {
- njs_uint32_to_string(&index, i);
-
- ret = njs_array_object_handler(vm, handler, args, &index, i);
+ ret = njs_array_object_handler(vm, handler, args, NULL, i);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
@@ -1777,10 +1802,10 @@ njs_array_reverse_iterator(njs_vm_t *vm,
njs_array_iterator_handler_t handler)
{
double idx;
- uint32_t i, from, to, length;
+ uint64_t i, from, to, length;
njs_int_t ret;
- njs_array_t *keys;
- njs_value_t *entry, *value, character, index, string_obj;
+ njs_array_t *array, *keys;
+ njs_value_t *entry, *value, prop, character, string_obj;
njs_object_t *object;
const u_char *p, *end, *pos;
njs_string_prop_t string_prop;
@@ -1790,16 +1815,34 @@ njs_array_reverse_iterator(njs_vm_t *vm,
to = args->to;

if (njs_is_array(value)) {
- if (njs_slow_path(!njs_is_fast_array(value))) {
- goto process_object;
- }
-
- i = from + 1;
-
- while (i-- > to) {
- entry = &njs_array_start(value)[i];
-
- ret = handler(vm, args, entry, i);
+ array = njs_array(value);
+
+ from += 1;
+
+ while (from-- > to) {
+ if (njs_slow_path(!array->object.fast_array)) {
+ goto process_object;
+ }
+
+ if (njs_fast_path(from < array->length
+ && njs_is_valid(&array->start[from])))
+ {
+ ret = handler(vm, args, &array->start[from], from);
+
+ } else {
+ entry = njs_value_arg(&njs_value_invalid);
+ ret = njs_value_property_i64(vm, value, from, &prop);
+ if (njs_slow_path(ret != NJS_DECLINED)) {
+ if (ret == NJS_ERROR) {
+ return NJS_ERROR;
+ }
+
+ entry = &prop;
+ }
+
+ ret = handler(vm, args, entry, from);
+ }
+
if (njs_slow_path(ret != NJS_OK)) {
if (ret > 0) {
return NJS_DECLINED;
@@ -1828,7 +1871,7 @@ njs_array_reverse_iterator(njs_vm_t *vm,
value = njs_object_value(value);
}

- length = (uint32_t) njs_string_prop(&string_prop, value);
+ length = njs_string_prop(&string_prop, value);
end = string_prop.start + string_prop.size;

if (length == string_prop.size) {
@@ -1921,9 +1964,7 @@ process_object:
i = from + 1;

while (i-- > to) {
- njs_uint32_to_string(&index, i);
-
- ret = njs_array_object_handler(vm, handler, args, &index, i);
+ ret = njs_array_object_handler(vm, handler, args, NULL, i);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
@@ -1964,11 +2005,9 @@ njs_array_prototype_concat(njs_vm_t *vm,
njs_index_t unused)
{
double idx;
- uint32_t len;
- uint64_t length;
+ uint64_t i, k, len, length;
njs_int_t ret;
- njs_uint_t i, k;
- njs_value_t this, index, retval, *value, *e;
+ njs_value_t this, retval, *value, *e;
njs_array_t *array, *keys;

ret = njs_value_to_object(vm, &args[0]);
@@ -2002,7 +2041,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
return ret;
}

- if (njs_slow_path((length + len) >= NJS_ARRAY_MAX_LENGTH53)) {
+ if (njs_slow_path((length + len) > NJS_MAX_LENGTH)) {
njs_type_error(vm, "Invalid length");
return NJS_ERROR;
}
@@ -2014,9 +2053,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
value = &njs_array_start(e)[k];

if (njs_slow_path(!njs_is_valid(value))) {
- njs_uint32_to_string(&index, k);
- ret = njs_value_property(vm, e, &index,
- &retval);
+ ret = njs_value_property_i64(vm, e, k, &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2039,9 +2076,7 @@ njs_array_prototype_concat(njs_vm_t *vm,

if (njs_fast_object(len)) {
for (k = 0; k < len; k++, length++) {
- njs_uint32_to_string(&index, k);
-
- ret = njs_value_property(vm, e, &index, &retval);
+ ret = njs_value_property_i64(vm, e, k, &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2050,9 +2085,8 @@ njs_array_prototype_concat(njs_vm_t *vm,
continue;
}

- njs_uint32_to_string(&index, length);
-
- ret = njs_value_property_set(vm, &this, &index, &retval);
+ ret = njs_value_property_i64_set(vm, &this, length,
+ &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2072,12 +2106,10 @@ njs_array_prototype_concat(njs_vm_t *vm,
return ret;
}

- idx = njs_string_to_index(&keys->start[k]);
+ idx = njs_string_to_index(&keys->start[k]) + length;

if (ret == NJS_OK) {
- njs_uint32_to_string(&index, length + idx);
-
- ret = njs_value_property_set(vm, &this, &index, &retval);
+ ret = njs_value_property_i64_set(vm, &this, idx, &retval);
if (njs_slow_path(ret == NJS_ERROR)) {
njs_array_destroy(vm, keys);
return ret;
@@ -2092,7 +2124,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
continue;
}

- if (njs_slow_path((length + len) >= NJS_ARRAY_MAX_LENGTH53)) {
+ if (njs_slow_path((length + len) >= NJS_MAX_LENGTH)) {
njs_type_error(vm, "Invalid length");
return NJS_ERROR;
}
@@ -2104,9 +2136,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
}

} else {
- njs_uint32_to_string(&index, length);
-
- ret = njs_value_property_set(vm, &this, &index, e);
+ ret = njs_value_property_i64_set(vm, &this, length, e);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2128,7 +2158,7 @@ njs_array_prototype_concat(njs_vm_t *vm,

static njs_int_t
njs_array_handler_index_of(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
if (njs_values_strict_equal(args->argument, entry)) {
njs_set_number(&vm->retval, n);
@@ -2145,7 +2175,7 @@ njs_array_prototype_index_of(njs_vm_t *v
njs_index_t unused)
{
int64_t from;
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_array_iterator_args_t iargs;

@@ -2180,12 +2210,12 @@ njs_array_prototype_index_of(njs_vm_t *v
}
}

- iargs.from = (uint32_t) from;
+ iargs.from = from;
iargs.to = length;

ret = njs_array_iterator(vm, &iargs, njs_array_handler_index_of);
- if (njs_fast_path(ret == NJS_DECLINED)) {
- return NJS_OK;
+ if (njs_fast_path(ret != NJS_OK)) {
+ return (ret == NJS_DECLINED) ? NJS_OK : NJS_ERROR;
}

not_found:
@@ -2201,7 +2231,7 @@ njs_array_prototype_last_index_of(njs_vm
njs_uint_t nargs, njs_index_t unused)
{
int64_t from;
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_array_iterator_args_t iargs;

@@ -2234,7 +2264,7 @@ njs_array_prototype_last_index_of(njs_vm
}

if (from >= 0) {
- from = njs_min(from, length - 1);
+ from = njs_min((uint64_t) from, length - 1);

} else if (from < 0) {
from += length;
@@ -2248,8 +2278,8 @@ njs_array_prototype_last_index_of(njs_vm
iargs.to = 0;

ret = njs_array_reverse_iterator(vm, &iargs, njs_array_handler_index_of);
- if (njs_fast_path(ret == NJS_DECLINED)) {
- return NJS_OK;
+ if (njs_fast_path(ret != NJS_OK)) {
+ return (ret == NJS_DECLINED) ? NJS_OK : NJS_ERROR;
}

not_found:
@@ -2262,7 +2292,7 @@ not_found:

static njs_int_t
njs_array_handler_includes(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
if (!njs_is_valid(entry)) {
entry = njs_value_arg(&njs_value_undefined);
@@ -2283,7 +2313,7 @@ njs_array_prototype_includes(njs_vm_t *v
njs_index_t unused)
{
int64_t from;
- uint32_t length;
+ uint64_t length;
njs_int_t ret;
njs_array_iterator_args_t iargs;

@@ -2318,12 +2348,12 @@ njs_array_prototype_includes(njs_vm_t *v
}
}

- iargs.from = (uint32_t) from;
+ iargs.from = from;
iargs.to = length;

ret = njs_array_iterator(vm, &iargs, njs_array_handler_includes);
- if (njs_fast_path(ret == NJS_DECLINED)) {
- return NJS_OK;
+ if (njs_fast_path(ret != NJS_OK)) {
+ return (ret == NJS_DECLINED) ? NJS_OK : NJS_ERROR;
}

not_found:
@@ -2338,11 +2368,10 @@ static njs_int_t
njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- int64_t start, end;
- uint32_t length;
- njs_int_t i, ret;
+ int64_t i, length, start, end;
+ njs_int_t ret;
njs_array_t *array;
- njs_value_t name, *this, *value;
+ njs_value_t *this, *value;

this = njs_argument(args, 0);

@@ -2358,7 +2387,7 @@ njs_array_prototype_fill(njs_vm_t *vm, n
length = array->length;

} else {
- ret = njs_object_length(vm, this, &length);
+ ret = njs_object_length(vm, this, (uint64_t *) &length);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2398,9 +2427,7 @@ njs_array_prototype_fill(njs_vm_t *vm, n
value = njs_arg(args, nargs, 1);

while (start < end) {
- njs_uint32_to_string(&name, start++);
-
- ret = njs_value_property_set(vm, this, &name, value);
+ ret = njs_value_property_i64_set(vm, this, start++, value);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
@@ -2442,7 +2469,7 @@ njs_array_validate_args(njs_vm_t *vm, nj
return ret;
}

- ret = njs_value_length(vm, iargs->value, &iargs->to);
+ ret = njs_value_length(vm, iargs->value, (uint64_t *) &iargs->to);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
@@ -2467,7 +2494,7 @@ failed:

static njs_int_t
njs_array_handler_for_each(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
if (njs_is_valid(entry)) {
return njs_array_iterator_call(vm, args, entry, n);
@@ -2502,7 +2529,7 @@ njs_array_prototype_for_each(njs_vm_t *v

static njs_int_t
njs_array_handler_some(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;

@@ -2550,7 +2577,7 @@ njs_array_prototype_some(njs_vm_t *vm, n

static njs_int_t
njs_array_handler_every(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;

@@ -2598,7 +2625,7 @@ njs_array_prototype_every(njs_vm_t *vm,

static njs_int_t
njs_array_handler_filter(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;
njs_value_t copy;
@@ -2654,7 +2681,7 @@ njs_array_prototype_filter(njs_vm_t *vm,

static njs_int_t
njs_array_handler_find(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;
njs_value_t copy;
@@ -2708,7 +2735,7 @@ njs_array_prototype_find(njs_vm_t *vm, n

static njs_int_t
njs_array_handler_find_index(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;
njs_value_t copy;
@@ -2762,11 +2789,11 @@ njs_array_prototype_find_index(njs_vm_t

static njs_int_t
njs_array_handler_map(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;
njs_array_t *retval;
- njs_value_t this, key;
+ njs_value_t this;

retval = args->array;

@@ -2786,9 +2813,8 @@ njs_array_handler_map(njs_vm_t *vm, njs_

} else {
njs_set_array(&this, retval);
- njs_uint32_to_string(&key, n);
-
- ret = njs_value_property_set(vm, &this, &key, &vm->retval);
+
+ ret = njs_value_property_i64_set(vm, &this, n, &vm->retval);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
@@ -2804,7 +2830,7 @@ static njs_int_t
njs_array_prototype_map(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- uint32_t length, i;
+ uint64_t length, i;
njs_int_t ret;
njs_array_t *array;
njs_value_t *this;
@@ -2870,7 +2896,7 @@ unexpected_args:

njs_inline njs_int_t
njs_array_iterator_reduce(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_value_t arguments[5];

@@ -2888,7 +2914,7 @@ njs_array_iterator_reduce(njs_vm_t *vm,

static njs_int_t
njs_array_handler_reduce(njs_vm_t *vm, njs_array_iterator_args_t *args,
- njs_value_t *entry, uint32_t n)
+ njs_value_t *entry, uint64_t n)
{
njs_int_t ret;

@@ -2960,7 +2986,7 @@ njs_array_prototype_reduce_right(njs_vm_
return ret;
}

- ret = njs_value_length(vm, iargs.value, &iargs.from);
+ ret = njs_value_length(vm, iargs.value, (uint64_t *) &iargs.from);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
@@ -3019,8 +3045,8 @@ unexpected_args:


static njs_int_t
-njs_array_string_sort(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
+njs_array_string_sort(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+ njs_index_t unused)
{
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Style: removing excessive commentaries.

$
0
0
details: https://hg.nginx.org/njs/rev/cbc09d7edfc8
branches:
changeset: 1327:cbc09d7edfc8
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Feb 17 16:18:18 2020 +0300
description:
Style: removing excessive commentaries.

diffstat:

src/njs_array.c | 10 -------
src/njs_array_buffer.c | 5 ---
src/njs_boolean.c | 3 --
src/njs_date.c | 3 --
src/njs_dtoa_fixed.c | 10 -------
src/njs_error.c | 27 -------------------
src/njs_function.c | 10 -------
src/njs_math.c | 17 ------------
src/njs_number.c | 12 --------
src/njs_object.c | 26 ------------------
src/njs_regexp.c | 3 --
src/njs_string.c | 69 --------------------------------------------------
src/njs_symbol.c | 18 -------------
13 files changed, 0 insertions(+), 213 deletions(-)

diffs (truncated from 1324 to 1000 lines):

diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_array.c
--- a/src/njs_array.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_array.c Mon Feb 17 16:18:18 2020 +0300
@@ -444,7 +444,6 @@ njs_array_of(njs_vm_t *vm, njs_value_t *

static const njs_object_prop_t njs_array_constructor_properties[] =
{
- /* Array.name == "Array". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -452,7 +451,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* Array.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -460,14 +458,12 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* Array.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
.value = njs_prop_handler(njs_object_prototype_create),
},

- /* Array.isArray(). */
{
.type = NJS_PROPERTY,
.name = njs_string("isArray"),
@@ -476,8 +472,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ES6. */
- /* Array.of(). */
{
.type = NJS_PROPERTY,
.name = njs_string("of"),
@@ -3403,7 +3397,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ES7. */
{
.type = NJS_PROPERTY,
.name = njs_string("includes"),
@@ -3436,7 +3429,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("fill"),
@@ -3453,7 +3445,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("find"),
@@ -3462,7 +3453,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("findIndex"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_array_buffer.c
--- a/src/njs_array_buffer.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_array_buffer.c Mon Feb 17 16:18:18 2020 +0300
@@ -112,7 +112,6 @@ njs_array_buffer_is_view(njs_vm_t *vm, n

static const njs_object_prop_t njs_array_buffer_constructor_properties[] =
{
- /* ArrayBuffer.name == "ArrayBuffer". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -120,7 +119,6 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ArrayBuffer.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -128,14 +126,12 @@ static const njs_object_prop_t njs_arra
.configurable = 1,
},

- /* ArrayBuffer.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
.value = njs_prop_handler(njs_object_prototype_create),
},

- /* ArrayBuffer[Symbol.species] */
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
@@ -147,7 +143,6 @@ static const njs_object_prop_t njs_arra
.enumerable = 0,
},

- /* ArrayBuffer.isView(new Uint8Array()) === true */
{
.type = NJS_PROPERTY,
.name = njs_string("isView"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_boolean.c
--- a/src/njs_boolean.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_boolean.c Mon Feb 17 16:18:18 2020 +0300
@@ -40,7 +40,6 @@ njs_boolean_constructor(njs_vm_t *vm, nj

static const njs_object_prop_t njs_boolean_constructor_properties[] =
{
- /* Boolean.name == "Boolean". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -48,7 +47,6 @@ static const njs_object_prop_t njs_bool
.configurable = 1,
},

- /* Boolean.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -56,7 +54,6 @@ static const njs_object_prop_t njs_bool
.configurable = 1,
},

- /* Boolean.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_date.c
--- a/src/njs_date.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_date.c Mon Feb 17 16:18:18 2020 +0300
@@ -1057,7 +1057,6 @@ njs_date_number_parse(int64_t *value, co

static const njs_object_prop_t njs_date_constructor_properties[] =
{
- /* Date.name == "Date". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -1065,7 +1064,6 @@ static const njs_object_prop_t njs_date
.configurable = 1,
},

- /* Date.length == 7. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -1073,7 +1071,6 @@ static const njs_object_prop_t njs_date
.configurable = 1,
},

- /* Date.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_dtoa_fixed.c
--- a/src/njs_dtoa_fixed.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_dtoa_fixed.c Mon Feb 17 16:18:18 2020 +0300
@@ -378,16 +378,6 @@ njs_fixed_dtoa(double value, njs_uint_t

dividend = significand;

- /*
- * Let v = f * 2^e with f == significand and e == exponent.
- * Then need q (quotient) and r (remainder) as follows:
- * f * 2^e = q * 5^17 * 2^17 + r
- * If e > 17 then
- * f * 2^(e-17) = q * 5^17 + r/2^17
- * else
- * f = q * 5^17 * 2^(17-e) + r/2^e
- */
-
if (exponent > 17) {
/* (e - 17) <= 3. */
dividend <<= exponent - 17;
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_error.c
--- a/src/njs_error.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_error.c Mon Feb 17 16:18:18 2020 +0300
@@ -297,7 +297,6 @@ njs_error_constructor(njs_vm_t *vm, njs_

static const njs_object_prop_t njs_error_constructor_properties[] =
{
- /* Error.name == "Error". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -305,7 +304,6 @@ static const njs_object_prop_t njs_erro
.configurable = 1,
},

- /* Error.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -313,7 +311,6 @@ static const njs_object_prop_t njs_erro
.configurable = 1,
},

- /* Error.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -338,7 +335,6 @@ njs_eval_error_constructor(njs_vm_t *vm,

static const njs_object_prop_t njs_eval_error_constructor_properties[] =
{
- /* EvalError.name == "EvalError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -346,7 +342,6 @@ static const njs_object_prop_t njs_eval
.configurable = 1,
},

- /* EvalError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -354,7 +349,6 @@ static const njs_object_prop_t njs_eval
.configurable = 1,
},

- /* EvalError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -379,7 +373,6 @@ njs_internal_error_constructor(njs_vm_t

static const njs_object_prop_t njs_internal_error_constructor_properties[] =
{
- /* InternalError.name == "InternalError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -387,7 +380,6 @@ static const njs_object_prop_t njs_inte
.configurable = 1,
},

- /* InternalError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -395,7 +387,6 @@ static const njs_object_prop_t njs_inte
.configurable = 1,
},

- /* InternalError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -420,7 +411,6 @@ njs_range_error_constructor(njs_vm_t *vm

static const njs_object_prop_t njs_range_error_constructor_properties[] =
{
- /* RangeError.name == "RangeError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -428,7 +418,6 @@ static const njs_object_prop_t njs_rang
.configurable = 1,
},

- /* RangeError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -436,7 +425,6 @@ static const njs_object_prop_t njs_rang
.configurable = 1,
},

- /* RangeError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -461,7 +449,6 @@ njs_reference_error_constructor(njs_vm_t

static const njs_object_prop_t njs_reference_error_constructor_properties[] =
{
- /* ReferenceError.name == "ReferenceError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -469,7 +456,6 @@ static const njs_object_prop_t njs_refe
.configurable = 1,
},

- /* ReferenceError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -477,7 +463,6 @@ static const njs_object_prop_t njs_refe
.configurable = 1,
},

- /* ReferenceError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -502,7 +487,6 @@ njs_syntax_error_constructor(njs_vm_t *v

static const njs_object_prop_t njs_syntax_error_constructor_properties[] =
{
- /* SyntaxError.name == "SyntaxError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -510,7 +494,6 @@ static const njs_object_prop_t njs_synt
.configurable = 1,
},

- /* SyntaxError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -518,7 +501,6 @@ static const njs_object_prop_t njs_synt
.configurable = 1,
},

- /* SyntaxError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -543,7 +525,6 @@ njs_type_error_constructor(njs_vm_t *vm,

static const njs_object_prop_t njs_type_error_constructor_properties[] =
{
- /* TypeError.name == "TypeError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -551,7 +532,6 @@ static const njs_object_prop_t njs_type
.configurable = 1,
},

- /* TypeError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -559,7 +539,6 @@ static const njs_object_prop_t njs_type
.configurable = 1,
},

- /* TypeError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -584,7 +563,6 @@ njs_uri_error_constructor(njs_vm_t *vm,

static const njs_object_prop_t njs_uri_error_constructor_properties[] =
{
- /* URIError.name == "URIError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -592,7 +570,6 @@ static const njs_object_prop_t njs_uri_
.configurable = 1,
},

- /* URIError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -600,7 +577,6 @@ static const njs_object_prop_t njs_uri_
.configurable = 1,
},

- /* URIError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -686,7 +662,6 @@ njs_memory_error_prototype_create(njs_vm

static const njs_object_prop_t njs_memory_error_constructor_properties[] =
{
- /* MemoryError.name == "MemoryError". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -694,7 +669,6 @@ static const njs_object_prop_t njs_memo
.configurable = 1,
},

- /* MemoryError.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -702,7 +676,6 @@ static const njs_object_prop_t njs_memo
.configurable = 1,
},

- /* MemoryError.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_function.c
--- a/src/njs_function.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_function.c Mon Feb 17 16:18:18 2020 +0300
@@ -217,9 +217,6 @@ njs_function_copy(njs_vm_t *vm, njs_func
}


-/*
- * ES5.1, 10.6: CreateArgumentsObject.
- */
njs_int_t
njs_function_arguments_object_init(njs_vm_t *vm, njs_native_frame_t *frame)
{
@@ -973,7 +970,6 @@ njs_function_constructor(njs_vm_t *vm, n

static const njs_object_prop_t njs_function_constructor_properties[] =
{
- /* Function.name == "Function". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -981,7 +977,6 @@ static const njs_object_prop_t njs_func
.configurable = 1,
},

- /* Function.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -989,7 +984,6 @@ static const njs_object_prop_t njs_func
.configurable = 1,
},

- /* Function.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
@@ -1004,10 +998,6 @@ const njs_object_init_t njs_function_co
};


-/*
- * ES5.1, 15.3.5.1 length
- * the typical number of arguments expected by the function.
- */
static njs_int_t
njs_function_instance_length(njs_vm_t *vm, njs_object_prop_t *prop,
njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_math.c
--- a/src/njs_math.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_math.c Mon Feb 17 16:18:18 2020 +0300
@@ -1063,7 +1063,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("acosh"),
@@ -1080,7 +1079,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("asinh"),
@@ -1105,7 +1103,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("atanh"),
@@ -1114,7 +1111,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("cbrt"),
@@ -1131,7 +1127,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("clz32"),
@@ -1148,7 +1143,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("cosh"),
@@ -1165,7 +1159,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("expm1"),
@@ -1182,7 +1175,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("fround"),
@@ -1191,7 +1183,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("hypot"),
@@ -1200,7 +1191,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("imul"),
@@ -1217,7 +1207,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("log10"),
@@ -1226,7 +1215,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("log1p"),
@@ -1235,7 +1223,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("log2"),
@@ -1284,7 +1271,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("sign"),
@@ -1301,7 +1287,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("sinh"),
@@ -1326,7 +1311,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("tanh"),
@@ -1335,7 +1319,6 @@ static const njs_object_prop_t njs_math
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("trunc"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_number.c
--- a/src/njs_number.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_number.c Mon Feb 17 16:18:18 2020 +0300
@@ -420,7 +420,6 @@ njs_number_is_finite(njs_vm_t *vm, njs_v

static const njs_object_prop_t njs_number_constructor_properties[] =
{
- /* Number.name == "Number". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -428,7 +427,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* Number.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -436,28 +434,24 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* Number.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
.value = njs_prop_handler(njs_object_prototype_create),
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("EPSILON"),
.value = njs_value(NJS_NUMBER, 1, DBL_EPSILON),
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_long_string("MAX_SAFE_INTEGER"),
.value = njs_value(NJS_NUMBER, 1, NJS_MAX_SAFE_INTEGER),
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_long_string("MIN_SAFE_INTEGER"),
@@ -494,7 +488,6 @@ static const njs_object_prop_t njs_numb
.value = njs_value(NJS_NUMBER, 1, -INFINITY),
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("isFinite"),
@@ -503,7 +496,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("isInteger"),
@@ -512,7 +504,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("isSafeInteger"),
@@ -521,7 +512,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("isNaN"),
@@ -530,7 +520,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("parseFloat"),
@@ -539,7 +528,6 @@ static const njs_object_prop_t njs_numb
.configurable = 1,
},

- /* ES6. */
{
.type = NJS_PROPERTY,
.name = njs_string("parseInt"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_object.c
--- a/src/njs_object.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_object.c Mon Feb 17 16:18:18 2020 +0300
@@ -2084,7 +2084,6 @@ njs_property_prototype_create(njs_vm_t *

static const njs_object_prop_t njs_object_constructor_properties[] =
{
- /* Object.name == "Object". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -2092,7 +2091,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -2100,14 +2098,12 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
.value = njs_prop_handler(njs_object_prototype_create),
},

- /* Object.create(). */
{
.type = NJS_PROPERTY,
.name = njs_string("create"),
@@ -2116,7 +2112,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.keys(). */
{
.type = NJS_PROPERTY,
.name = njs_string("keys"),
@@ -2125,7 +2120,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* ES8: Object.values(). */
{
.type = NJS_PROPERTY,
.name = njs_string("values"),
@@ -2134,7 +2128,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* ES8: Object.entries(). */
{
.type = NJS_PROPERTY,
.name = njs_string("entries"),
@@ -2143,7 +2136,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.defineProperty(). */
{
.type = NJS_PROPERTY,
.name = njs_string("defineProperty"),
@@ -2152,7 +2144,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.defineProperties(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("defineProperties"),
@@ -2161,7 +2152,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.getOwnPropertyDescriptor(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("getOwnPropertyDescriptor"),
@@ -2170,7 +2160,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.getOwnPropertyDescriptors(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("getOwnPropertyDescriptors"),
@@ -2180,7 +2169,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.getOwnPropertyNames(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("getOwnPropertyNames"),
@@ -2190,7 +2178,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.getOwnPropertySymbols(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("getOwnPropertySymbols"),
@@ -2200,7 +2187,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.getPrototypeOf(). */
{
.type = NJS_PROPERTY,
.name = njs_string("getPrototypeOf"),
@@ -2209,7 +2195,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.setPrototypeOf(). */
{
.type = NJS_PROPERTY,
.name = njs_string("setPrototypeOf"),
@@ -2218,7 +2203,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.freeze(). */
{
.type = NJS_PROPERTY,
.name = njs_string("freeze"),
@@ -2227,7 +2211,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.isFrozen(). */
{
.type = NJS_PROPERTY,
.name = njs_string("isFrozen"),
@@ -2236,7 +2219,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.seal(). */
{
.type = NJS_PROPERTY,
.name = njs_string("seal"),
@@ -2245,7 +2227,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.isSealed(). */
{
.type = NJS_PROPERTY,
.name = njs_string("isSealed"),
@@ -2254,7 +2235,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.preventExtensions(). */
{
.type = NJS_PROPERTY,
.name = njs_long_string("preventExtensions"),
@@ -2263,7 +2243,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.isExtensible(). */
{
.type = NJS_PROPERTY,
.name = njs_string("isExtensible"),
@@ -2272,7 +2251,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.assign(). */
{
.type = NJS_PROPERTY,
.name = njs_string("assign"),
@@ -2281,7 +2259,6 @@ static const njs_object_prop_t njs_obje
.configurable = 1,
},

- /* Object.is(). */
{
.type = NJS_PROPERTY,
.name = njs_string("is"),
@@ -2298,9 +2275,6 @@ const njs_object_init_t njs_object_cons
};


-/*
- * ES6, 9.1.2: [[SetPrototypeOf]].
- */
static njs_int_t
njs_object_set_prototype(njs_vm_t *vm, njs_object_t *object,
const njs_value_t *value)
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_regexp.c
--- a/src/njs_regexp.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_regexp.c Mon Feb 17 16:18:18 2020 +0300
@@ -1224,7 +1224,6 @@ njs_regexp_string_create(njs_vm_t *vm, n

static const njs_object_prop_t njs_regexp_constructor_properties[] =
{
- /* RegExp.name == "RegExp". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -1232,7 +1231,6 @@ static const njs_object_prop_t njs_rege
.configurable = 1,
},

- /* RegExp.length == 2. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -1240,7 +1238,6 @@ static const njs_object_prop_t njs_rege
.configurable = 1,
},

- /* RegExp.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
diff -r 13dbdff9b76f -r cbc09d7edfc8 src/njs_string.c
--- a/src/njs_string.c Mon Feb 17 16:13:43 2020 +0300
+++ b/src/njs_string.c Mon Feb 17 16:18:18 2020 +0300
@@ -581,7 +581,6 @@ njs_string_constructor(njs_vm_t *vm, njs

static const njs_object_prop_t njs_string_constructor_properties[] =
{
- /* String.name == "String". */
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
@@ -589,7 +588,6 @@ static const njs_object_prop_t njs_stri
.configurable = 1,
},

- /* String.length == 1. */
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
@@ -597,14 +595,12 @@ static const njs_object_prop_t njs_stri
.configurable = 1,
},

- /* String.prototype. */
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_string("prototype"),
.value = njs_prop_handler(njs_object_prototype_create),
},

- /* String.bytesFrom(). */
{
.type = NJS_PROPERTY,
.name = njs_string("bytesFrom"),
@@ -613,7 +609,6 @@ static const njs_object_prop_t njs_stri
.configurable = 1,
},

- /* String.fromCharCode(). */
{
.type = NJS_PROPERTY,
.name = njs_string("fromCharCode"),
@@ -622,7 +617,6 @@ static const njs_object_prop_t njs_stri
.configurable = 1,
},

- /* String.fromCodePoint(), ECMAScript 6. */
{
.type = NJS_PROPERTY,
.name = njs_string("fromCodePoint"),
@@ -869,11 +863,6 @@ njs_string_prototype_to_string(njs_vm_t
}


-/*
- * String.concat(string2[, ..., stringN]).
- * JavaScript 1.2, ECMAScript 3.
- */
-
njs_int_t
njs_string_prototype_concat(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
@@ -1168,11 +1157,6 @@ njs_string_prototype_to_bytes(njs_vm_t *
}


-/*
- * String.slice(start[, end]).
- * JavaScript 1.2, ECMAScript 3.
- */
-
static njs_int_t
njs_string_prototype_slice(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
@@ -1195,11 +1179,6 @@ njs_string_prototype_slice(njs_vm_t *vm,
}


-/*
- * String.substring(start[, end]).
- * JavaScript 1.0, ECMAScript 1.
- */
-
static njs_int_t
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Simplified code using magic arguments introduced in 6df48738a043.

$
0
0
details: https://hg.nginx.org/njs/rev/db3a66bd71c1
branches:
changeset: 1328:db3a66bd71c1
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Feb 17 16:18:38 2020 +0300
description:
Simplified code using magic arguments introduced in 6df48738a043.

This reduces code duplication and the binary size.

diffstat:

src/njs_error.c | 92 +---
src/njs_math.c | 1136 ++++++++++++-----------------------------------------
src/njs_string.c | 118 +----
3 files changed, 306 insertions(+), 1040 deletions(-)

diffs (truncated from 1853 to 1000 lines):

diff -r cbc09d7edfc8 -r db3a66bd71c1 src/njs_error.c
--- a/src/njs_error.c Mon Feb 17 16:18:18 2020 +0300
+++ b/src/njs_error.c Mon Feb 17 16:18:38 2020 +0300
@@ -257,8 +257,8 @@ memory_error:


static njs_int_t
-njs_error_create(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_object_type_t type)
+njs_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+ njs_index_t type)
{
njs_int_t ret;
njs_value_t *value;
@@ -287,14 +287,6 @@ njs_error_create(njs_vm_t *vm, njs_value
}


-static njs_int_t
-njs_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_ERROR);
-}
-
-
static const njs_object_prop_t njs_error_constructor_properties[] =
{
{
@@ -325,14 +317,6 @@ const njs_object_init_t njs_error_const
};


-static njs_int_t
-njs_eval_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_EVAL_ERROR);
-}
-
-
static const njs_object_prop_t njs_eval_error_constructor_properties[] =
{
{
@@ -363,14 +347,6 @@ const njs_object_init_t njs_eval_error_
};


-static njs_int_t
-njs_internal_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_INTERNAL_ERROR);
-}
-
-
static const njs_object_prop_t njs_internal_error_constructor_properties[] =
{
{
@@ -401,14 +377,6 @@ const njs_object_init_t njs_internal_er
};


-static njs_int_t
-njs_range_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_RANGE_ERROR);
-}
-
-
static const njs_object_prop_t njs_range_error_constructor_properties[] =
{
{
@@ -439,14 +407,6 @@ const njs_object_init_t njs_range_error
};


-static njs_int_t
-njs_reference_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_REF_ERROR);
-}
-
-
static const njs_object_prop_t njs_reference_error_constructor_properties[] =
{
{
@@ -477,14 +437,6 @@ const njs_object_init_t njs_reference_e
};


-static njs_int_t
-njs_syntax_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_SYNTAX_ERROR);
-}
-
-
static const njs_object_prop_t njs_syntax_error_constructor_properties[] =
{
{
@@ -515,14 +467,6 @@ const njs_object_init_t njs_syntax_erro
};


-static njs_int_t
-njs_type_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_TYPE_ERROR);
-}
-
-
static const njs_object_prop_t njs_type_error_constructor_properties[] =
{
{
@@ -553,14 +497,6 @@ const njs_object_init_t njs_type_error_
};


-static njs_int_t
-njs_uri_error_constructor(njs_vm_t *vm, njs_value_t *args,
- njs_uint_t nargs, njs_index_t unused)
-{
- return njs_error_create(vm, args, nargs, NJS_OBJ_TYPE_URI_ERROR);
-}
-
-
static const njs_object_prop_t njs_uri_error_constructor_properties[] =
{
{
@@ -874,7 +810,8 @@ const njs_object_init_t njs_error_proto


const njs_object_type_init_t njs_error_type_init = {
- .constructor = njs_native_ctor(njs_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_ERROR),
.constructor_props = &njs_error_constructor_init,
.prototype_props = &njs_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -916,7 +853,8 @@ const njs_object_init_t njs_eval_error_


const njs_object_type_init_t njs_eval_error_type_init = {
- .constructor = njs_native_ctor(njs_eval_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_EVAL_ERROR),
.constructor_props = &njs_eval_error_constructor_init,
.prototype_props = &njs_eval_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -978,7 +916,8 @@ const njs_object_init_t njs_internal_er


const njs_object_type_init_t njs_internal_error_type_init = {
- .constructor = njs_native_ctor(njs_internal_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_INTERNAL_ERROR),
.constructor_props = &njs_internal_error_constructor_init,
.prototype_props = &njs_internal_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -1028,7 +967,8 @@ const njs_object_init_t njs_range_error


const njs_object_type_init_t njs_range_error_type_init = {
- .constructor = njs_native_ctor(njs_range_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_RANGE_ERROR),
.constructor_props = &njs_range_error_constructor_init,
.prototype_props = &njs_range_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -1070,7 +1010,8 @@ const njs_object_init_t njs_reference_e


const njs_object_type_init_t njs_reference_error_type_init = {
- .constructor = njs_native_ctor(njs_reference_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_REF_ERROR),
.constructor_props = &njs_reference_error_constructor_init,
.prototype_props = &njs_reference_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -1112,7 +1053,8 @@ const njs_object_init_t njs_syntax_erro


const njs_object_type_init_t njs_syntax_error_type_init = {
- .constructor = njs_native_ctor(njs_syntax_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_SYNTAX_ERROR),
.constructor_props = &njs_syntax_error_constructor_init,
.prototype_props = &njs_syntax_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -1154,7 +1096,8 @@ const njs_object_init_t njs_type_error_


const njs_object_type_init_t njs_type_error_type_init = {
- .constructor = njs_native_ctor(njs_type_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_TYPE_ERROR),
.constructor_props = &njs_type_error_constructor_init,
.prototype_props = &njs_type_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
@@ -1196,7 +1139,8 @@ const njs_object_init_t njs_uri_error_p


const njs_object_type_init_t njs_uri_error_type_init = {
- .constructor = njs_native_ctor(njs_uri_error_constructor, 1, 0),
+ .constructor = njs_native_ctor(njs_error_constructor, 1,
+ NJS_OBJ_TYPE_URI_ERROR),
.constructor_props = &njs_uri_error_constructor_init,
.prototype_props = &njs_uri_error_prototype_init,
.prototype_value = { .object = { .type = NJS_OBJECT } },
diff -r cbc09d7edfc8 -r db3a66bd71c1 src/njs_math.c
--- a/src/njs_math.c Mon Feb 17 16:18:18 2020 +0300
+++ b/src/njs_math.c Mon Feb 17 16:18:38 2020 +0300
@@ -8,444 +8,267 @@
#include <njs_main.h>


-static njs_int_t
-njs_object_math_abs(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, fabs(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_acos(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- double num;
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- num = njs_number(&args[1]);
-
-#if (NJS_SOLARIS)
- /* On Solaris acos(x) returns 0 for x > 1. */
- if (fabs(num) > 1.0) {
- num = NAN;
- }
-#endif
-
- njs_set_number(&vm->retval, acos(num));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_acosh(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, acosh(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_asin(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- double num;
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- num = njs_number(&args[1]);
-
-#if (NJS_SOLARIS)
- /* On Solaris asin(x) returns 0 for x > 1. */
- if (fabs(num) > 1.0) {
- num = NAN;
- }
-#endif
-
- njs_set_number(&vm->retval, asin(num));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_asinh(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, asinh(njs_number(&args[1])));
-
- return NJS_OK;
-}
+typedef enum {
+ NJS_MATH_ABS,
+ NJS_MATH_ACOS,
+ NJS_MATH_ACOSH,
+ NJS_MATH_ASIN,
+ NJS_MATH_ASINH,
+ NJS_MATH_ATAN,
+ NJS_MATH_ATAN2,
+ NJS_MATH_ATANH,
+ NJS_MATH_CBRT,
+ NJS_MATH_CEIL,
+ NJS_MATH_CLZ32,
+ NJS_MATH_COS,
+ NJS_MATH_COSH,
+ NJS_MATH_EXP,
+ NJS_MATH_EXPM1,
+ NJS_MATH_FLOOR,
+ NJS_MATH_FROUND,
+ NJS_MATH_IMUL,
+ NJS_MATH_LOG,
+ NJS_MATH_LOG10,
+ NJS_MATH_LOG1P,
+ NJS_MATH_LOG2,
+ NJS_MATH_POW,
+ NJS_MATH_ROUND,
+ NJS_MATH_SIGN,
+ NJS_MATH_SIN,
+ NJS_MATH_SINH,
+ NJS_MATH_SQRT,
+ NJS_MATH_TAN,
+ NJS_MATH_TANH,
+ NJS_MATH_TRUNC,
+} njs_math_func_t;


static njs_int_t
-njs_object_math_atan(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
+njs_object_math_func(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+ njs_index_t magic)
{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, atan(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_atan2(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- double y, x;
- njs_int_t ret;
+ double num, num2;
+ uint8_t sign;
+ uint32_t u32;
+ uint64_t one, fraction_mask;
+ njs_int_t ret, ep;
+ njs_math_func_t func;
+ njs_diyfp_conv_t conv;

- if (njs_slow_path(nargs < 3)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- if (njs_slow_path(!njs_is_number(&args[2]))) {
- ret = njs_value_to_numeric(vm, &args[2], &args[2]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
+ func = magic;

- y = njs_number(&args[1]);
- x = njs_number(&args[2]);
-
- njs_set_number(&vm->retval, atan2(y, x));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_atanh(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
+ ret = njs_value_to_number(vm, njs_arg(args, nargs, 1), &num);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return ret;
}

- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
+ switch (func) {
+ case NJS_MATH_ABS:
+ num = fabs(num);
+ break;
+
+ case NJS_MATH_ACOS:
+#if (NJS_SOLARIS)
+ /* On Solaris acos(x) returns 0 for x > 1. */
+ if (fabs(num) > 1.0) {
+ num = NAN;
}
- }
+#endif

- njs_set_number(&vm->retval, atanh(njs_number(&args[1])));
+ num = acos(num);
+ break;
+
+ case NJS_MATH_ACOSH:
+ num = acosh(num);
+ break;

- return NJS_OK;
-}
+ case NJS_MATH_ASIN:
+#if (NJS_SOLARIS)
+ /* On Solaris asin(x) returns 0 for x > 1. */
+ if (fabs(num) > 1.0) {
+ num = NAN;
+ }
+#endif
+
+ num = asin(num);
+ break;

+ case NJS_MATH_ASINH:
+ num = asinh(num);
+ break;
+
+ case NJS_MATH_ATAN:
+ num = atan(num);
+ break;
+
+ case NJS_MATH_ATANH:
+ num = atanh(num);
+ break;

-static njs_int_t
-njs_object_math_cbrt(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
+ case NJS_MATH_CBRT:
+ num = cbrt(num);
+ break;
+
+ case NJS_MATH_CEIL:
+ num = ceil(num);
+ break;

- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
+ case NJS_MATH_CLZ32:
+ u32 = njs_number_to_uint32(num);
+ num = njs_leading_zeros(u32);
+ break;
+
+ case NJS_MATH_COS:
+ num = cos(num);
+ break;
+
+ case NJS_MATH_COSH:
+ num = cosh(num);
+ break;

- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
+ case NJS_MATH_EXP:
+ num = exp(num);
+ break;
+
+ case NJS_MATH_EXPM1:
+ num = expm1(num);
+ break;
+
+ case NJS_MATH_FLOOR:
+ num = floor(num);
+ break;

- njs_set_number(&vm->retval, cbrt(njs_number(&args[1])));
+ case NJS_MATH_FROUND:
+ num = (float) num;
+ break;

- return NJS_OK;
-}
+ case NJS_MATH_LOG:
+ num = log(num);
+ break;

+ case NJS_MATH_LOG10:
+ num = log10(num);
+ break;

-static njs_int_t
-njs_object_math_ceil(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
+ case NJS_MATH_LOG1P:
+ num = log1p(num);
+ break;
+
+ case NJS_MATH_LOG2:
+#if (NJS_SOLARIS)
+ /* On Solaris 10 log(-1) returns -Infinity. */
+ if (num < 0) {
+ num = NAN;
+ }
+#endif
+
+ num = log2(num);
+ break;
+
+ case NJS_MATH_SIGN:
+ if (!isnan(num) && num != 0) {
+ num = signbit(num) ? -1 : 1;
+ }

- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
+ break;
+
+ case NJS_MATH_SIN:
+ num = sin(num);
+ break;
+
+ case NJS_MATH_SINH:
+ num = sinh(num);
+ break;

- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
+ case NJS_MATH_SQRT:
+ num = sqrt(num);
+ break;
+
+ case NJS_MATH_ROUND:
+ conv.d = num;
+ ep = (conv.u64 & NJS_DBL_EXPONENT_MASK) >> NJS_DBL_SIGNIFICAND_SIZE;
+
+ if (ep < NJS_DBL_EXPONENT_OFFSET) {
+
+ /* |v| < 1. */

- njs_set_number(&vm->retval, ceil(njs_number(&args[1])));
+ if (ep == (NJS_DBL_EXPONENT_OFFSET - 1)
+ && conv.u64 != njs_uint64(0xbfe00000, 0x00000000))
+ {
+ /* (|v| > 0.5 || v == 0.5) => +-1.0 */
+
+ conv.u64 = conv.u64 & NJS_DBL_SIGN_MASK;
+ conv.u64 |= NJS_DBL_EXPONENT_OFFSET << NJS_DBL_SIGNIFICAND_SIZE;
+
+ } else {

- return NJS_OK;
-}
+ /* (|v| < 0.5 || v == -0.5) => +-0. */
+
+ conv.u64 &= ((uint64_t) 1) << 63;
+ }

+ } else if (ep < NJS_DBL_EXPONENT_BIAS) {
+
+ /* |v| <= 2^52 - 1 (largest safe integer). */
+
+ one = ((uint64_t) 1) << (NJS_DBL_EXPONENT_BIAS - ep);
+ fraction_mask = one - 1;

-static njs_int_t
-njs_object_math_clz32(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- uint32_t ui32;
- njs_int_t ret;
+ /* truncation. */
+
+ sign = conv.u64 >> 63;
+ conv.u64 += (one >> 1) - sign;
+ conv.u64 &= ~fraction_mask;
+ }
+
+ num = conv.d;
+ break;

- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, 32);
- return NJS_OK;
- }
+ case NJS_MATH_TAN:
+ num = tan(num);
+ break;

- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_uint32(vm, &args[1], &ui32);
+ case NJS_MATH_TANH:
+ num = tanh(num);
+ break;
+
+ case NJS_MATH_TRUNC:
+ num = trunc(num);
+ break;
+
+ default:
+ ret = njs_value_to_number(vm, njs_arg(args, nargs, 2), &num2);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}

- } else {
- ui32 = njs_number_to_uint32(njs_number(&args[1]));
- }
-
- njs_set_number(&vm->retval, njs_leading_zeros(ui32));
-
- return NJS_OK;
-}
-
+ switch (func) {
+ case NJS_MATH_ATAN2:
+ num = atan2(num, num2);
+ break;

-static njs_int_t
-njs_object_math_cos(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
+ case NJS_MATH_IMUL:
+ u32 = njs_number_to_uint32(num);
+ num = (int32_t) (u32 * njs_number_to_uint32(num2));
+ break;

- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, cos(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
+ default:
+ /*
+ * According to ECMA-262:
+ * 1. If exponent is NaN, the result should be NaN;
+ * 2. The result of Math.pow(+/-1, +/-Infinity) should be NaN.
+ */

-static njs_int_t
-njs_object_math_cosh(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
+ if (fabs(num) != 1 || (!isnan(num2) && !isinf(num2))) {
+ num = pow(num, num2);

- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
+ } else {
+ num = NAN;
+ }
}
}

- njs_set_number(&vm->retval, cosh(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_exp(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, exp(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_expm1(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, expm1(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_floor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, floor(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_fround(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, (float) njs_number(&args[1]));
+ njs_set_number(&vm->retval, num);

return NJS_OK;
}
@@ -459,21 +282,22 @@ njs_object_math_hypot(njs_vm_t *vm, njs_
njs_int_t ret;
njs_uint_t i;

- for (i = 1; i < nargs; i++) {
- if (!njs_is_numeric(&args[i])) {
- ret = njs_value_to_numeric(vm, &args[i], &args[i]);
- if (ret != NJS_OK) {
- return ret;
- }
- }
+ ret = njs_value_to_number(vm, njs_arg(args, nargs, 1), &num);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return ret;
}

- num = (nargs > 1) ? fabs(njs_number(&args[1])) : 0;
+ num = (nargs > 1) ? fabs(num) : 0;

for (i = 2; i < nargs; i++) {
+ ret = njs_value_to_numeric(vm, &args[i], &args[i]);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return ret;
+ }
+
num = hypot(num, njs_number(&args[i]));

- if (num == INFINITY) {
+ if (njs_slow_path(isinf(num))) {
break;
}
}
@@ -484,150 +308,6 @@ njs_object_math_hypot(njs_vm_t *vm, njs_
}


-static njs_int_t
-njs_object_math_imul(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- uint32_t a, b;
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 3)) {
- njs_set_number(&vm->retval, 0);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_uint32(vm, &args[1], &a);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
-
- } else {
- a = njs_number_to_uint32(njs_number(&args[1]));
- }
-
- if (njs_slow_path(!njs_is_number(&args[2]))) {
- ret = njs_value_to_uint32(vm, &args[2], &b);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
-
- } else {
- b = njs_number_to_uint32(njs_number(&args[2]));
- }
-
- njs_set_number(&vm->retval, (int32_t) (a * b));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
-
- njs_set_number(&vm->retval, log(njs_number(&args[1])));
-
- return NJS_OK;
-}
-
-
-static njs_int_t
-njs_object_math_log10(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
- njs_index_t unused)
-{
- njs_int_t ret;
-
- if (njs_slow_path(nargs < 2)) {
- njs_set_number(&vm->retval, NAN);
- return NJS_OK;
- }
-
- if (njs_slow_path(!njs_is_number(&args[1]))) {
- ret = njs_value_to_numeric(vm, &args[1], &args[1]);
- if (njs_slow_path(ret != NJS_OK)) {
- return ret;
- }
- }
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Fixed potential integer-overflow in String.prototype.replace().

$
0
0
details: https://hg.nginx.org/njs/rev/d2877d602d39
branches:
changeset: 1329:d2877d602d39
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Feb 17 16:18:40 2020 +0300
description:
Fixed potential integer-overflow in String.prototype.replace().

diffstat:

src/njs_string.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diffs (20 lines):

diff -r db3a66bd71c1 -r d2877d602d39 src/njs_string.c
--- a/src/njs_string.c Mon Feb 17 16:18:38 2020 +0300
+++ b/src/njs_string.c Mon Feb 17 16:18:40 2020 +0300
@@ -3672,10 +3672,16 @@ njs_string_replace_regexp_function(njs_v
njs_value_t *arguments;
njs_string_prop_t string;

+ if (njs_slow_path((n + 3) >= UINT32_MAX / sizeof(njs_value_t))) {
+ njs_memory_error(vm);
+ return NJS_ERROR;
+ }
+
njs_set_invalid(&r->retval);

arguments = njs_mp_alloc(vm->mem_pool, (n + 3) * sizeof(njs_value_t));
if (njs_slow_path(arguments == NULL)) {
+ njs_memory_error(vm);
return NJS_ERROR;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Re: NGINX Mailproxy

$
0
0
Hello!

On Mon, Feb 17, 2020 at 11:40:45AM +0100, Fabian Joël Flückiger wrote:

> I am trying to use nginx as reverse-mailproxy for multiple
> mailservers.Whenever I have a client which connects to the
> nginx-mailproxy via STARTLS or SSL, the NGINX passes a malformed
> LOGIN packets to the backend mailserver, per example:
> (nginx = nginx, mails = backend mailserver, in the first case
> MailEnable, in the second case Dovecot)
>
> nginx>5 LOGIN {18}
> mails>+ go ahead
> nginx>user@domain.tld {8}
> mails>+ go ahead
> nginx>PASSWORD
> mails>BAD UNKNOWN Command
>
> nginx>3 LOGIN {17}
> mails> + OK
> nginx> user@domain.tld {8}
> mails> + OK
> nginx>PASSWORD
> mails>3 NO [AUTHENTICATIONFAILED] Authentication failed.
>
>
> As you can see, nginx adds a suffix to the username, which lets
> the backendserver fail. Wireshark displays this additional data
> as {number}, I can also provide the hex variant of the packets.
> NGINX also adds this suffix, if the username is passed via NGX
> auth header.
> I've tested this with the nginx-full binary from the ubuntu
> repositories, as well as a self-compiled binary.

The "{18}" part is a part of the IMAP literal syntax, see here:

https://tools.ietf.org/html/rfc3501#section-4.3

It is certainly recognized by both backends used in the examples
above. While MailEnable response looks incorrect (it should start
with tag "5" followed by a space), this is probably an artifact of
manual translation of packets into the message. Dovecot's one is
perfectly correct and clearly says that authentication failed.

Most likely the problem is that LOGIN authentication is disabled
on your backends, or it requires SSL or STARTTLS to work (and it
does not work, since nginx uses plaintext connections to the
backends). Check the configuration and logs of your backends to
find out the exact reason.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Failed disk + proxy_intercept_errors

$
0
0
Hello!

On Fri, Feb 14, 2020 at 04:14:28AM -0500, chocholo3 wrote:

> Thanks a lot for your response.
> From what you are saying I understand another option:
>
> current server section - Server A
> copy the same configuration and use some other spare drive as a
> proxy_cache_path configure that as - Server B
>
> Configure both server sections to listen on unix socket instead of network.
>
> Create a third server C configuration that will listen on network and will
> proxy_path to Server A with proxy_intercept_errors on and error_page served
> from location that will proxy_path to Server B.
>
> Is something like this supposed to work? Or it would be better to have the
> there completely independent configuration (like to use some other software
> for server C).
>
> (I'm asking because I did something like that i the past and it broke a bad
> way. It started serving 500 to everyone. I kind of fear to try it in
> production again.)

As I already tried to explain in the previous message, there are
edge cases which cannot be solved by error handling, at all.

As long as you only care about disk errors which happen before
sending response headers and result in serving 500, just
error_page should be enough. Using additional proxying layer
might help to cover some additional errors which happen during
sending first bytes of the response body.

The only perfect solution, however, is to use disk-level
redundancy - for example, a simple software mirror on two disks is
trivial to configure and will help a lot.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Config file for Picocms on Yunohost with a permanent redirect

$
0
0
Hello,

Can you help me to make it working ?

I'm trying to setup url rewriting with Picocms.
When I activate it, it works but I have a 404 on css, js and assets.

Here is my config :

rewrite ^/site$ /site/ permanent;

location /site/ {
alias /var/www/webapp/main_site/ ;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
index index.html index.php ;
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm-webapp_main_site.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
# when activated urls are ok /site/content/sub instead of /site/?content/?sub
fastcgi_param PICO_URL_REWRITING 1;
}

location ~ ^/site/ {
try_files $uri $uri/ /site/index.php$is_args$args;
}

}

The css, js, etc are under /var/www/webapp/main_site/themes/default/…
The assets are under /var/www/webapp/main_site/assets/…

I tried to understand how it works, but it's above my understanding and try / test different things was not successful until now.

So some help / advises would be nice.

Thanks

RE: Google QUIC support in nginx

$
0
0
Test

From: nginx <nginx-bounces@nginx.org> On Behalf Of Mathew Heard
Sent: 2020年1月10日星期五 上午10:30
To: nginx@nginx.org
Subject: Fwd: Google QUIC support in nginx

Hey nginx team,

How does the roadmap now look given the Cloudflare Quiche "experiment" release? Is QUIC/HTTP3 still scheduled for mainline?

On Fri, 31 May 2019 at 16:54, George <nginx-forum@forum.nginx.org<mailto:nginx-forum@forum.nginx.org>> wrote:
Roadmap suggests it is in Nginx 1.17 mainline QUIC = HTTP/3
https://trac.nginx.org/nginx/roadmap :)

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,256352,284367#msg-284367

_______________________________________________
nginx mailing list
nginx@nginx.org<mailto:nginx@nginx.org>
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Two sites listening on same port simultaneously with different location (context) not workig

$
0
0
I installed gitlab in behind nginx reverse proxy and it worked fine. Added the below configuration. Note that location path was changed.

upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}

server {
listen 0.0.0.0:80 default_server;
listen [::]:80 default_server;
server_name abcd.com;
server_tokens off;
root /opt/gitlab/embedded/service/gitlab-rails/public;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log debug;

location /gitlab {
client_max_body_size 0;
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
}
}
While testing gitlab, I deleted default file soft link from nginx sites-enabled.

I created the soft link again the configuration is as follows: Note that default_server is removed her and location path is "/"

server {
listen 0.0.0.0:80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log debug;
location / {
try_files $uri $uri/ =404;
}
}

Now while accessing my VM ip http://x.y.z.a, I am getting "403 Forbidden" error in the browser. However gitlab still working. How to get both the sites working listening on port 80 but with different context of location?

RE: Two sites listening on same port simultaneously with different location (context) not workig

$
0
0
> Now while accessing my VM ip http://x.y.z.a, I am getting "403 Forbidden"
> error in the browser. However gitlab still working. How to get both the sites
> working listening on port 80 but with different context of location?

First of all you should check the error log to see why the 403 is returned and it usually gives the idea what is happening and which server {} block nginx is using and what file/location is being served.


> While testing gitlab, I deleted default file soft link from nginx sites-enabled.
> I created the soft link again the configuration is as follows: Note that default_server is removed her and location path is "/"

Second, it's a bit unclear what is your current nginx configuration is (nginx -T should display the "compiled" configuration with all the includes)
(depending on where 'include sites-enabled/*' is placed in the main config the behavior can change)

But in general virtualhosts (sites listening on the same ip/port) are distinguished by the 'server_name' - if a non-defined domain (or bare ip) is pointed to nginx - then either the virtualhost with 'default' / 'default_server' OR by order in the configuration first server {} block is used.

Most likely your gitlab server{} comes first and when you open your vm ip http://x.y.z.a nginx is trying to use /opt/gitlab/embedded/service/gitlab-rails/public but since there is probably no index file and/or maybe has no permissions 403 is returned.



Each server {} uses its own location blocks .. So if you want to have both '/' and '/gitlab' from the same ip/host you need to place them in the same server{}.

Somethine like:

server {
listen 0.0.0.0:80;
listen [::]:80;
root /var/www/html;
....
location / {
try_files $uri $uri/ =404;
}

location /gitlab {
proxy_pass http://gitlab-workhorse;
...
}
}

p.s. from my own experience it's more simple to host Gitlab from own (sub)domain rather than to configure as a subdirectory.

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Hello all

$
0
0
Hello, I am Maxi, from Argentina (my english is very poor), and I found this forum looking a solution for an error installing NGINX. I am not a professional programmer, but I enjoy it very much.

I´d been starting with linux, Ubuntu particulary in the 90's looking for something different in my adol time, now I am trying to install my first invoice web server, to help in my work.

Thanks for your read.

Maxi

[njs] Detecting memory error in njs_chb_*() functions.

$
0
0
details: https://hg.nginx.org/njs/rev/aa9ac79f7fd9
branches:
changeset: 1330:aa9ac79f7fd9
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Feb 18 18:41:38 2020 +0300
description:
Detecting memory error in njs_chb_*() functions.

diffstat:

src/njs_array.c | 9 +++++++--
src/njs_chb.c | 17 ++++++++++++-----
src/njs_chb.h | 12 ++++++++++--
src/njs_json.c | 14 ++++++++------
4 files changed, 37 insertions(+), 15 deletions(-)

diffs (158 lines):

diff -r d2877d602d39 -r aa9ac79f7fd9 src/njs_array.c
--- a/src/njs_array.c Mon Feb 17 16:18:40 2020 +0300
+++ b/src/njs_array.c Tue Feb 18 18:41:38 2020 +0300
@@ -1381,8 +1381,8 @@ njs_array_prototype_join(njs_vm_t *vm, n
njs_index_t unused)
{
u_char *p, *last;
- int64_t length;
- uint64_t i, len, size;
+ int64_t size, length;
+ uint64_t i, len;
njs_int_t ret;
njs_chb_t chain;
njs_utf8_t utf8;
@@ -1497,6 +1497,11 @@ njs_array_prototype_join(njs_vm_t *vm, n
njs_chb_drop(&chain, separator.size);

size = njs_chb_size(&chain);
+ if (njs_slow_path(size < 0)) {
+ njs_memory_error(vm);
+ return NJS_ERROR;
+ }
+
length -= separator.length;

p = njs_string_alloc(vm, &vm->retval, size, utf8 ? length : 0);
diff -r d2877d602d39 -r aa9ac79f7fd9 src/njs_chb.c
--- a/src/njs_chb.c Mon Feb 17 16:18:40 2020 +0300
+++ b/src/njs_chb.c Tue Feb 18 18:41:38 2020 +0300
@@ -134,9 +134,13 @@ njs_chb_drain(njs_chb_t *chain, size_t d
void
njs_chb_drop(njs_chb_t *chain, size_t drop)
{
- size_t size;
+ uint64_t size;
njs_chb_node_t *n, *next;

+ if (njs_slow_path(chain->error)) {
+ return;
+ }
+
n = chain->last;

if (njs_fast_path(n != NULL && (njs_chb_node_size(n) > drop))) {
@@ -145,7 +149,7 @@ njs_chb_drop(njs_chb_t *chain, size_t dr
}

n = chain->nodes;
- size = njs_chb_size(chain);
+ size = (uint64_t) njs_chb_size(chain);

if (drop >= size) {
njs_chb_destroy(chain);
@@ -181,10 +185,10 @@ njs_int_t
njs_chb_join(njs_chb_t *chain, njs_str_t *str)
{
u_char *start;
- size_t size;
+ uint64_t size;
njs_chb_node_t *n;

- if (chain->error) {
+ if (njs_slow_path(chain->error)) {
return NJS_DECLINED;
}

@@ -196,7 +200,10 @@ njs_chb_join(njs_chb_t *chain, njs_str_t
return NJS_OK;
}

- size = njs_chb_size(chain);
+ size = (uint64_t) njs_chb_size(chain);
+ if (njs_slow_path(size >= UINT32_MAX)) {
+ return NJS_ERROR;
+ }

start = njs_mp_alloc(chain->pool, size);
if (njs_slow_path(start == NULL)) {
diff -r d2877d602d39 -r aa9ac79f7fd9 src/njs_chb.h
--- a/src/njs_chb.h Mon Feb 17 16:18:40 2020 +0300
+++ b/src/njs_chb.h Tue Feb 18 18:41:38 2020 +0300
@@ -61,12 +61,16 @@ njs_chb_init(njs_chb_t *chain, njs_mp_t
}


-njs_inline uint64_t
+njs_inline int64_t
njs_chb_size(njs_chb_t *chain)
{
uint64_t size;
njs_chb_node_t *n;

+ if (njs_slow_path(chain->error)) {
+ return -1;
+ }
+
n = chain->nodes;

size = 0;
@@ -86,6 +90,10 @@ njs_chb_utf8_length(njs_chb_t *chain)
int64_t len, length;
njs_chb_node_t *n;

+ if (njs_slow_path(chain->error)) {
+ return -1;
+ }
+
n = chain->nodes;

length = 0;
@@ -93,7 +101,7 @@ njs_chb_utf8_length(njs_chb_t *chain)
while (n != NULL) {
len = njs_utf8_length(n->start, njs_chb_node_size(n));
if (njs_slow_path(len < 0)) {
- return len;
+ return 0;
}

length += len;
diff -r d2877d602d39 -r aa9ac79f7fd9 src/njs_json.c
--- a/src/njs_json.c Mon Feb 17 16:18:40 2020 +0300
+++ b/src/njs_json.c Tue Feb 18 18:41:38 2020 +0300
@@ -1120,8 +1120,7 @@ njs_json_stringify_iterator(njs_vm_t *vm
njs_value_t *object)
{
u_char *p;
- int64_t length;
- uint64_t size;
+ int64_t size, length;
njs_int_t ret;
njs_chb_t chain;
njs_value_t *key, *value, index, wrapper;
@@ -1295,18 +1294,21 @@ done:
}

size = njs_chb_size(&chain);
- if (njs_slow_path(size == 0)) {
+ if (njs_slow_path(size < 0)) {
+ njs_chb_destroy(&chain);
+ goto memory_error;
+ }
+
+ if (size == 0) {
njs_set_undefined(&vm->retval);
goto release;
}

length = njs_chb_utf8_length(&chain);
- if (njs_slow_path(length < 0)) {
- length = 0;
- }

p = njs_string_alloc(vm, &vm->retval, size, length);
if (njs_slow_path(p == NULL)) {
+ njs_chb_destroy(&chain);
goto memory_error;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Fixed njs_json_append_string().

$
0
0
details: https://hg.nginx.org/njs/rev/9b70f038abfa
branches:
changeset: 1331:9b70f038abfa
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Feb 18 18:42:37 2020 +0300
description:
Fixed njs_json_append_string().

diffstat:

src/njs_json.c | 91 ++++++++++++++++++++++++++-------------------------------
1 files changed, 42 insertions(+), 49 deletions(-)

diffs (128 lines):

diff -r aa9ac79f7fd9 -r 9b70f038abfa src/njs_json.c
--- a/src/njs_json.c Tue Feb 18 18:41:38 2020 +0300
+++ b/src/njs_json.c Tue Feb 18 18:42:37 2020 +0300
@@ -1545,37 +1545,50 @@ njs_json_append_value(njs_chb_t *chain,
static void
njs_json_append_string(njs_chb_t *chain, const njs_value_t *value, char quote)
{
+ size_t size;
u_char c, *dst, *dst_end;
- size_t length;
+ njs_bool_t utf8;
const u_char *p, *end;
- njs_string_prop_t str;
-
- static char hex2char[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
- (void) njs_string_prop(&str, value);
-
- p = str.start;
- end = p + str.size;
- length = str.length;
-
- dst = njs_chb_reserve(chain, length + 2);
+ njs_string_prop_t string;
+
+ static char hex2char[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ (void) njs_string_prop(&string, value);
+
+ p = string.start;
+ end = p + string.size;
+ utf8 = (string.length != 0 && string.length != string.size);
+
+ size = njs_max(string.size + 2, 7);
+ dst = njs_chb_reserve(chain, string.size + 2);
if (njs_slow_path(dst == NULL)) {
return;
}

- dst_end = dst + length + 2;
+ dst_end = dst + size;

*dst++ = quote;
+ njs_chb_written(chain, 1);

while (p < end) {
-
- if (*p < ' '
- || *p == '\\'
- || (*p == '\"' && quote == '\"'))
+ if (njs_slow_path(dst_end <= dst + njs_length("\\uXXXX"))) {
+ size = njs_max(end - p + 1, 6);
+ dst = njs_chb_reserve(chain, size);
+ if (njs_slow_path(dst == NULL)) {
+ return;
+ }
+
+ dst_end = dst + size;
+ }
+
+ if (njs_slow_path(*p < ' '
+ || *p == '\\'
+ || (*p == '\"' && quote == '\"')))
{
c = (u_char) *p++;
*dst++ = '\\';
+ njs_chb_written(chain, 2);

switch (c) {
case '\\':
@@ -1605,44 +1618,24 @@ njs_json_append_string(njs_chb_t *chain,
*dst++ = '0';
*dst++ = hex2char[(c & 0xf0) >> 4];
*dst++ = hex2char[c & 0x0f];
- }
- }
-
- /*
- * Control characters less than space are encoded using 6 bytes
- * "\uXXXX". Checking there is at least 6 bytes of destination storage
- * space.
- */
-
- while (p < end && (dst_end - dst) > 6) {
- if (*p < ' ' || (*p == '\"' && quote == '\"') || *p == '\\') {
- break;
+ njs_chb_written(chain, 4);
}

- if (length != 0) {
- /* UTF-8 or ASCII string. */
- dst = njs_utf8_copy(dst, &p, end);
-
- } else {
- /* Byte string. */
- *dst++ = *p++;
- }
+ continue;
}

- if (dst_end - dst <= 6) {
- njs_chb_written(chain, dst - chain->last->pos);
-
- dst = njs_chb_reserve(chain, 64);
- if (njs_slow_path(dst == NULL)) {
- return;
- }
-
- dst_end = dst + 64;
+ if (utf8) {
+ /* UTF-8 string. */
+ dst = njs_utf8_copy(dst, &p, end);
+
+ } else {
+ /* Byte or ASCII string. */
+ *dst++ = *p++;
}
+
+ njs_chb_written(chain, dst - chain->last->pos);
}

- njs_chb_written(chain, dst - chain->last->pos);
-
njs_chb_append(chain, &quote, 1);
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Viewing all 53287 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>