Submitting a cgi-bin POST form results in "Null charset name" exception jetty-distribution-9.4.21.v20190926

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Submitting a cgi-bin POST form results in "Null charset name" exception jetty-distribution-9.4.21.v20190926

Gary Kopff
jetty-distribution-9.4.21.v20190926
jre1.8.0_231

Create a HTML form using the POST method :-

<form  name="frm" method=post action="http://your_company.com/your_company/cgi-bin/form.pl" accept-charset="utf-8">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

Submit the form.

Jetty throws the following exception :-

HTTP ERROR 500 java.lang.IllegalArgumentException: Null charset name

URI: /your_company/cgi-bin/form.pl
STATUS: 500
MESSAGE: java.lang.IllegalArgumentException: Null charset name
SERVLET: CGI
CAUSED BY: java.lang.IllegalArgumentException: Null charset name
java.lang.IllegalArgumentException: Null charset name
	at java.nio.charset.Charset.lookup(Charset.java:457)
	at java.nio.charset.Charset.forName(Charset.java:528)
	at org.eclipse.jetty.servlets.CGI.exec(CGI.java:254)
	at org.eclipse.jetty.servlets.CGI.service(CGI.java:217)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:760)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1589)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1296)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1559)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1211)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:500)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:386)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:560)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:378)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:914)
	at java.lang.Thread.run(Thread.java:748)

Relevant lines of code from /jetty/servlets/CGI.java were it determines that the POST method was used and
calls getCharacterEncoding on the request that results in the above exception :-
                   String bodyFormEncoded = null;

if ((HttpMethod.POST.is(req.getMethod()) || HttpMethod.PUT.is(req.getMethod())) && "application/x-www-form-urlencoded".equals(req.getContentType()))
        {
            MultiMap<String> parameterMap = new MultiMap<>();
            Enumeration<String> names = req.getParameterNames();
            while (names.hasMoreElements())
            {
                String parameterName = names.nextElement();
                parameterMap.addValues(parameterName, req.getParameterValues(parameterName));
            }
            bodyFormEncoded = UrlEncoded.encode(parameterMap, Charset.forName(req.getCharacterEncoding()), true);
        }


For some reason the request doesn't satisfy the javax.servlet HttpServletRequest getCharacterEncoding() method.

A call to CGI-exec with a POST request use to work without throwing an exception at least at jetty-distribution-9.4.14.v20181114.

Experimented but can't find a fix and appreciate any insight or possible workaround to appease jetty.servlets.CGI.exec()


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Submitting a cgi-bin POST form results in "Null charset name" exception jetty-distribution-9.4.21.v20190926

Lachlan Roberts
Hi,

This looks like a bug in jetty. I have opened an issue and PR for this.


On Wed, Oct 23, 2019 at 3:52 PM Gary Kopff <[hidden email]> wrote:
jetty-distribution-9.4.21.v20190926
jre1.8.0_231

Create a HTML form using the POST method :-

<form  name="frm" method=post action="http://your_company.com/your_company/cgi-bin/form.pl" accept-charset="utf-8">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

Submit the form.

Jetty throws the following exception :-

HTTP ERROR 500 java.lang.IllegalArgumentException: Null charset name

URI: /your_company/cgi-bin/form.pl
STATUS: 500
MESSAGE: java.lang.IllegalArgumentException: Null charset name
SERVLET: CGI
CAUSED BY: java.lang.IllegalArgumentException: Null charset name
java.lang.IllegalArgumentException: Null charset name
	at java.nio.charset.Charset.lookup(Charset.java:457)
	at java.nio.charset.Charset.forName(Charset.java:528)
	at org.eclipse.jetty.servlets.CGI.exec(CGI.java:254)
	at org.eclipse.jetty.servlets.CGI.service(CGI.java:217)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:760)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1589)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1296)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1559)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1211)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:500)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:386)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:560)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:378)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:914)
	at java.lang.Thread.run(Thread.java:748)

Relevant lines of code from /jetty/servlets/CGI.java were it determines that the POST method was used and
calls getCharacterEncoding on the request that results in the above exception :-
                   String bodyFormEncoded = null;

if ((HttpMethod.POST.is(req.getMethod()) || HttpMethod.PUT.is(req.getMethod())) && "application/x-www-form-urlencoded".equals(req.getContentType()))
        {
            MultiMap<String> parameterMap = new MultiMap<>();
            Enumeration<String> names = req.getParameterNames();
            while (names.hasMoreElements())
            {
                String parameterName = names.nextElement();
                parameterMap.addValues(parameterName, req.getParameterValues(parameterName));
            }
            bodyFormEncoded = UrlEncoded.encode(parameterMap, Charset.forName(req.getCharacterEncoding()), true);
        }


For some reason the request doesn't satisfy the javax.servlet HttpServletRequest getCharacterEncoding() method.

A call to CGI-exec with a POST request use to work without throwing an exception at least at jetty-distribution-9.4.14.v20181114.

Experimented but can't find a fix and appreciate any insight or possible workaround to appease jetty.servlets.CGI.exec()

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Submitting a cgi-bin POST form results in "Null charset name" exception jetty-distribution-9.4.21.v20190926

Brian Reichert
In reply to this post by Gary Kopff
On Wed, Oct 23, 2019 at 04:51:57AM +0000, Gary Kopff wrote:

> jetty-distribution-9.4.21.v20190926
> jre1.8.0_231
>
> Create a HTML form using the POST method :-
>
> <form  name="frm" method=post action="http://your_company.com/your_company/cgi-bin/form.pl" accept-charset="utf-8">
>   First name: <input type="text" name="fname"><br>
>   Last name: <input type="text" name="lname"><br>
>   <input type="submit" value="Submit">
> </form>
>
> Submit the form.
>
> Jetty throws the following exception :-
> HTTP ERROR 500 java.lang.IllegalArgumentException: Null charset name
> URI:    /your_company/cgi-bin/form.pl

Make sure you secretly don't have any wacky nulls or whitespace characters
in that HTML form.

> _______________________________________________
> jetty-users mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users


--
Brian Reichert <[hidden email]>
BSD admin/developer at large
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Submitting a cgi-bin POST form results in "Null charset name" exception jetty-distribution-9.4.21.v20190926

Lachlan Roberts
There is now a fix for this in the 9.4.x branch and will be in a 9.4.23 release.

For a workaround you should be able to use the RewriteHandler to default the charset to utf-8.

On Thu, Oct 24, 2019 at 2:25 AM Brian Reichert <[hidden email]> wrote:
On Wed, Oct 23, 2019 at 04:51:57AM +0000, Gary Kopff wrote:
> jetty-distribution-9.4.21.v20190926
> jre1.8.0_231
>
> Create a HTML form using the POST method :-
>
> <form  name="frm" method=post action="http://your_company.com/your_company/cgi-bin/form.pl" accept-charset="utf-8">
>   First name: <input type="text" name="fname"><br>
>   Last name: <input type="text" name="lname"><br>
>   <input type="submit" value="Submit">
> </form>
>
> Submit the form.
>
> Jetty throws the following exception :-
> HTTP ERROR 500 java.lang.IllegalArgumentException: Null charset name
> URI:    /your_company/cgi-bin/form.pl

Make sure you secretly don't have any wacky nulls or whitespace characters
in that HTML form.

> _______________________________________________
> jetty-users mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users


--
Brian Reichert                          <[hidden email]>
BSD admin/developer at large   
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users