Message ID | 20200626211359.8005-1-JPEWhacker@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | mongoose: Fix NULL pointer dereference in restart_handler | expand |
Hi Joshua, On 26.06.20 23:13, Joshua Watt wrote: > The restart_handler would crash when any non-HTTP event was processed > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the > other events are ignored. > Correct, thanks for fix. Tested-by : Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic > Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> > --- > mongoose/mongoose_interface.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c > index 150210e..a847cc8 100644 > --- a/mongoose/mongoose_interface.c > +++ b/mongoose/mongoose_interface.c > @@ -111,20 +111,20 @@ static void restart_handler(struct mg_connection *nc, int ev, void *ev_data) > struct http_message *hm = (struct http_message *) ev_data; > ipc_message msg = {}; > > - (void)ev; > + if (ev == MG_EV_HTTP_REQUEST) { > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > + mg_http_send_error(nc, 405, "Method Not Allowed"); > + return; > + } > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > - mg_http_send_error(nc, 405, "Method Not Allowed"); > - return; > - } > + int ret = ipc_postupdate(&msg); > + if (ret) { > + mg_http_send_error(nc, 500, "Failed to queue command"); > + return; > + } > > - int ret = ipc_postupdate(&msg); > - if (ret) { > - mg_http_send_error(nc, 500, "Failed to queue command"); > - return; > + mg_http_send_error(nc, 201, "Device will reboot now."); > } > - > - mg_http_send_error(nc, 201, "Device will reboot now."); > } > > static void broadcast_callback(struct mg_connection *nc, int ev, void *ev_data) >
Hi all, I have the following segfault, maybe this modification introduces it? (gdb) bt #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 #1 0x000056349213fde4 in restart_handler (nc=nc@entry=0x563492256f30, ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose_interface.c:116 #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, ev_data=ev_data@entry=0x0, user_data=<optimized out>) at mongoose/mongoose.c:2288 #3 0x000056349214d000 in mg_http_handler (nc=nc@entry=0x563492256f30, ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, ev=ev@entry=5, ev_data=ev_data@entry=0x0, user_data=<optimized out>) at mongoose/mongoose.c:2288 #5 0x000056349214e727 in mg_close_conn (conn=conn@entry=0x563492256f30) at mongoose/mongoose.c:2395 #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, fd_flags=<optimized out>, nc=0x563492256f30) at mongoose/mongoose.c:3885 #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized out>) at mongoose/mongoose.c:4116 #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 #10 0x00005634921404e1 in start_mongoose (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", argc=argc@entry=3, argv=argv@entry=0x56349223dab8) at mongoose/mongoose_interface.c:615 #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, task=<optimized out>, cmdline=0x0, start=0x563492140271 <start_mongoose>, av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 "/etc/swupdate.cfg", run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 #12 start_swupdate_subprocess (type=<optimized out>, name=0x56349216dd02 "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, cmdline=0x0) at core/pctl.c:180 #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at core/swupdate.c:938 I use swupdate with those arguments: /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f /etc/swupdate.cfg -H x86-vecow v1.0.0 -p reboot Best regards, Vincent Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > Hi Joshua, > > On 26.06.20 23:13, Joshua Watt wrote: > > The restart_handler would crash when any non-HTTP event was processed > > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the > > other events are ignored. > > > > Correct, thanks for fix. > > Tested-by : Stefano Babic <sba...@denx.de> > > Best regards, > Stefano Babic > > > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> > > --- > > mongoose/mongoose_interface.c | 22 +++++++++++----------- > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > diff --git a/mongoose/mongoose_interface.c > b/mongoose/mongoose_interface.c > > index 150210e..a847cc8 100644 > > --- a/mongoose/mongoose_interface.c > > +++ b/mongoose/mongoose_interface.c > > @@ -111,20 +111,20 @@ static void restart_handler(struct mg_connection > *nc, int ev, void *ev_data) > > struct http_message *hm = (struct http_message *) ev_data; > > ipc_message msg = {}; > > > > - (void)ev; > > + if (ev == MG_EV_HTTP_REQUEST) { > > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > > + mg_http_send_error(nc, 405, "Method Not Allowed"); > > + return; > > + } > > > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > > - mg_http_send_error(nc, 405, "Method Not Allowed"); > > - return; > > - } > > + int ret = ipc_postupdate(&msg); > > + if (ret) { > > + mg_http_send_error(nc, 500, "Failed to queue command"); > > + return; > > + } > > > > - int ret = ipc_postupdate(&msg); > > - if (ret) { > > - mg_http_send_error(nc, 500, "Failed to queue command"); > > - return; > > + mg_http_send_error(nc, 201, "Device will reboot now."); > > } > > - > > - mg_http_send_error(nc, 201, "Device will reboot now."); > > } > > > > static void broadcast_callback(struct mg_connection *nc, int ev, void > *ev_data) > > > > -- > ===================================================================== > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: +49-8142-66989-53 <+49%208142%206698953> Fax: +49-8142-66989-80 > <+49%208142%206698980> Email: sba...@denx.de > ===================================================================== >
And systemd-journald logs swupdate[403]: RUN [run_system_cmd] : reboot command returned 0 swupdate[403]: Child 423(webserver) killed by signal 11 swupdate[403]: Error write on socket ctrl systemd[1]: swupdate.service: Main process exited, code=exited, status=11/n/a systemd[1]: swupdate.service: Failed with result 'exit-code'. systemd[1]: Stopped SWUpdate daemon. Le jeudi 24 septembre 2020 à 11:52:13 UTC+2, vincent....@gmail.com a écrit : > Hi all, > > I have the following segfault, maybe this modification introduces it? > > (gdb) bt > #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, > str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 > #1 0x000056349213fde4 in restart_handler (nc=nc@entry=0x563492256f30, > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at > mongoose/mongoose_interface.c:116 > #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, > ev_data=ev_data@entry=0x0, > user_data=<optimized out>) at mongoose/mongoose.c:2288 > #3 0x000056349214d000 in mg_http_handler (nc=nc@entry=0x563492256f30, > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 > #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, > ev=ev@entry=5, > ev_data=ev_data@entry=0x0, user_data=<optimized out>) at > mongoose/mongoose.c:2288 > #5 0x000056349214e727 in mg_close_conn (conn=conn@entry=0x563492256f30) > at mongoose/mongoose.c:2395 > #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, > now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 > #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, > fd_flags=<optimized out>, nc=0x563492256f30) at mongoose/mongoose.c:3885 > #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized out>) > at mongoose/mongoose.c:4116 > #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, > timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 > #10 0x00005634921404e1 in start_mongoose > (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", > argc=argc@entry=3, argv=argv@entry=0x56349223dab8) > at mongoose/mongoose_interface.c:615 > #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, > task=<optimized out>, cmdline=0x0, start=0x563492140271 <start_mongoose>, > av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 "/etc/swupdate.cfg", > run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 > #12 start_swupdate_subprocess (type=<optimized out>, name=0x56349216dd02 > "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, > argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, > cmdline=0x0) at core/pctl.c:180 > #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, > name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, > argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 > #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at > core/swupdate.c:938 > > I use swupdate with those arguments: > > /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f /etc/swupdate.cfg -H > x86-vecow v1.0.0 -p reboot > > Best regards, > Vincent > > > Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > >> Hi Joshua, >> >> On 26.06.20 23:13, Joshua Watt wrote: >> > The restart_handler would crash when any non-HTTP event was processed >> > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the >> > other events are ignored. >> > >> >> Correct, thanks for fix. >> >> Tested-by : Stefano Babic <sba...@denx.de> >> >> Best regards, >> Stefano Babic >> >> > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> >> > --- >> > mongoose/mongoose_interface.c | 22 +++++++++++----------- >> > 1 file changed, 11 insertions(+), 11 deletions(-) >> > >> > diff --git a/mongoose/mongoose_interface.c >> b/mongoose/mongoose_interface.c >> > index 150210e..a847cc8 100644 >> > --- a/mongoose/mongoose_interface.c >> > +++ b/mongoose/mongoose_interface.c >> > @@ -111,20 +111,20 @@ static void restart_handler(struct mg_connection >> *nc, int ev, void *ev_data) >> > struct http_message *hm = (struct http_message *) ev_data; >> > ipc_message msg = {}; >> > >> > - (void)ev; >> > + if (ev == MG_EV_HTTP_REQUEST) { >> > + if(mg_vcasecmp(&hm->method, "POST") != 0) { >> > + mg_http_send_error(nc, 405, "Method Not Allowed"); >> > + return; >> > + } >> > >> > - if(mg_vcasecmp(&hm->method, "POST") != 0) { >> > - mg_http_send_error(nc, 405, "Method Not Allowed"); >> > - return; >> > - } >> > + int ret = ipc_postupdate(&msg); >> > + if (ret) { >> > + mg_http_send_error(nc, 500, "Failed to queue command"); >> > + return; >> > + } >> > >> > - int ret = ipc_postupdate(&msg); >> > - if (ret) { >> > - mg_http_send_error(nc, 500, "Failed to queue command"); >> > - return; >> > + mg_http_send_error(nc, 201, "Device will reboot now."); >> > } >> > - >> > - mg_http_send_error(nc, 201, "Device will reboot now."); >> > } >> > >> > static void broadcast_callback(struct mg_connection *nc, int ev, void >> *ev_data) >> > >> >> -- >> ===================================================================== >> DENX Software Engineering GmbH, Managing Director: Wolfgang Denk >> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany >> Phone: +49-8142-66989-53 <+49%208142%206698953> Fax: +49-8142-66989-80 >> <+49%208142%206698980> Email: sba...@denx.de >> ===================================================================== >> >
On 24.09.20 11:52, vincent....@gmail.com wrote: > Hi all, > > I have the following segfault, maybe this modification introduces it? Maybe not - Joshua's patch introduced a check, nothing more. You can revert his patch, you should still have the crash. How do you send the SWU ? Via a browser or via self written code ? It looks like you could send an http request with a null method. Best regards, Stefano Babic > > (gdb) bt > #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, > str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 > #1 0x000056349213fde4 in restart_handler (nc=nc@entry=0x563492256f30, > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at > mongoose/mongoose_interface.c:116 > #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, > ev_data=ev_data@entry=0x0, > user_data=<optimized out>) at mongoose/mongoose.c:2288 > #3 0x000056349214d000 in mg_http_handler (nc=nc@entry=0x563492256f30, > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 > #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, > ev=ev@entry=5, > ev_data=ev_data@entry=0x0, user_data=<optimized out>) at > mongoose/mongoose.c:2288 > #5 0x000056349214e727 in mg_close_conn (conn=conn@entry=0x563492256f30) > at mongoose/mongoose.c:2395 > #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, > now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 > #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, > fd_flags=<optimized out>, nc=0x563492256f30) at mongoose/mongoose.c:3885 > #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized > out>) at mongoose/mongoose.c:4116 > #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, > timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 > #10 0x00005634921404e1 in start_mongoose > (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", > argc=argc@entry=3, argv=argv@entry=0x56349223dab8) > at mongoose/mongoose_interface.c:615 > #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, > task=<optimized out>, cmdline=0x0, start=0x563492140271 <start_mongoose>, > av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 "/etc/swupdate.cfg", > run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 > #12 start_swupdate_subprocess (type=<optimized out>, name=0x56349216dd02 > "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, > argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, > cmdline=0x0) at core/pctl.c:180 > #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, > name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, > argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 > #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at > core/swupdate.c:938 > > I use swupdate with those arguments: > > /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f /etc/swupdate.cfg > -H x86-vecow v1.0.0 -p reboot > > Best regards, > Vincent > > > Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > > Hi Joshua, > > On 26.06.20 23:13, Joshua Watt wrote: > > The restart_handler would crash when any non-HTTP event was processed > > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the > > other events are ignored. > > > > Correct, thanks for fix. > > Tested-by : Stefano Babic <sba...@denx.de> > > Best regards, > Stefano Babic > > > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> > > --- > > mongoose/mongoose_interface.c | 22 +++++++++++----------- > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > diff --git a/mongoose/mongoose_interface.c > b/mongoose/mongoose_interface.c > > index 150210e..a847cc8 100644 > > --- a/mongoose/mongoose_interface.c > > +++ b/mongoose/mongoose_interface.c > > @@ -111,20 +111,20 @@ static void restart_handler(struct > mg_connection *nc, int ev, void *ev_data) > > struct http_message *hm = (struct http_message *) ev_data; > > ipc_message msg = {}; > > > > - (void)ev; > > + if (ev == MG_EV_HTTP_REQUEST) { > > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > > + mg_http_send_error(nc, 405, "Method Not Allowed"); > > + return; > > + } > > > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > > - mg_http_send_error(nc, 405, "Method Not Allowed"); > > - return; > > - } > > + int ret = ipc_postupdate(&msg); > > + if (ret) { > > + mg_http_send_error(nc, 500, "Failed to queue command"); > > + return; > > + } > > > > - int ret = ipc_postupdate(&msg); > > - if (ret) { > > - mg_http_send_error(nc, 500, "Failed to queue command"); > > - return; > > + mg_http_send_error(nc, 201, "Device will reboot now."); > > } > > - > > - mg_http_send_error(nc, 201, "Device will reboot now."); > > } > > > > static void broadcast_callback(struct mg_connection *nc, int ev, > void *ev_data) > > > > -- > ===================================================================== > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: +49-8142-66989-53 <tel:+49%208142%206698953> Fax: > +49-8142-66989-80 <tel:+49%208142%206698980> Email: sba...@denx.de > ===================================================================== > > -- > You received this message because you are subscribed to the Google > Groups "swupdate" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to swupdate+unsubscribe@googlegroups.com > <mailto:swupdate+unsubscribe@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com > <https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
I use SWU forwarder to send SWU files. I think mongoose restart_handler is called by swupdate-sysrestart, and ev_data is a null pointer so hm->method is invalid? Le jeudi 24 septembre 2020 à 13:38:06 UTC+2, Stefano Babic a écrit : > On 24.09.20 11:52, vincent....@gmail.com wrote: > > Hi all, > > > > I have the following segfault, maybe this modification introduces it? > > Maybe not - Joshua's patch introduced a check, nothing more. You can > revert his patch, you should still have the crash. > > How do you send the SWU ? Via a browser or via self written code ? It > looks like you could send an http request with a null method. > > Best regards, > Stefano Babic > > > > > (gdb) bt > > #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, > > str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 > > #1 0x000056349213fde4 in restart_handler (nc=nc@entry=0x563492256f30, > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at > > mongoose/mongoose_interface.c:116 > > #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, > > ev_data=ev_data@entry=0x0, > > user_data=<optimized out>) at mongoose/mongoose.c:2288 > > #3 0x000056349214d000 in mg_http_handler (nc=nc@entry=0x563492256f30, > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 > > #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, > > ev=ev@entry=5, > > ev_data=ev_data@entry=0x0, user_data=<optimized out>) at > > mongoose/mongoose.c:2288 > > #5 0x000056349214e727 in mg_close_conn (conn=conn@entry=0x563492256f30) > > at mongoose/mongoose.c:2395 > > #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, > > now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 > > #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, > > fd_flags=<optimized out>, nc=0x563492256f30) at mongoose/mongoose.c:3885 > > #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized > > out>) at mongoose/mongoose.c:4116 > > #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, > > timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 > > #10 0x00005634921404e1 in start_mongoose > > (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", > > argc=argc@entry=3, argv=argv@entry=0x56349223dab8) > > at mongoose/mongoose_interface.c:615 > > #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, > > task=<optimized out>, cmdline=0x0, start=0x563492140271 <start_mongoose>, > > av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 "/etc/swupdate.cfg", > > run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 > > #12 start_swupdate_subprocess (type=<optimized out>, name=0x56349216dd02 > > "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, > > argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, > > cmdline=0x0) at core/pctl.c:180 > > #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, > > name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, > > argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 > > #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at > > core/swupdate.c:938 > > > > I use swupdate with those arguments: > > > > /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f /etc/swupdate.cfg > > -H x86-vecow v1.0.0 -p reboot > > > > Best regards, > > Vincent > > > > > > Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > > > > Hi Joshua, > > > > On 26.06.20 23:13, Joshua Watt wrote: > > > The restart_handler would crash when any non-HTTP event was processed > > > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the > > > other events are ignored. > > > > > > > Correct, thanks for fix. > > > > Tested-by : Stefano Babic <sba...@denx.de> > > > > Best regards, > > Stefano Babic > > > > > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> > > > --- > > > mongoose/mongoose_interface.c | 22 +++++++++++----------- > > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > > > diff --git a/mongoose/mongoose_interface.c > > b/mongoose/mongoose_interface.c > > > index 150210e..a847cc8 100644 > > > --- a/mongoose/mongoose_interface.c > > > +++ b/mongoose/mongoose_interface.c > > > @@ -111,20 +111,20 @@ static void restart_handler(struct > > mg_connection *nc, int ev, void *ev_data) > > > struct http_message *hm = (struct http_message *) ev_data; > > > ipc_message msg = {}; > > > > > > - (void)ev; > > > + if (ev == MG_EV_HTTP_REQUEST) { > > > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > + mg_http_send_error(nc, 405, "Method Not Allowed"); > > > + return; > > > + } > > > > > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > - mg_http_send_error(nc, 405, "Method Not Allowed"); > > > - return; > > > - } > > > + int ret = ipc_postupdate(&msg); > > > + if (ret) { > > > + mg_http_send_error(nc, 500, "Failed to queue command"); > > > + return; > > > + } > > > > > > - int ret = ipc_postupdate(&msg); > > > - if (ret) { > > > - mg_http_send_error(nc, 500, "Failed to queue command"); > > > - return; > > > + mg_http_send_error(nc, 201, "Device will reboot now."); > > > } > > > - > > > - mg_http_send_error(nc, 201, "Device will reboot now."); > > > } > > > > > > static void broadcast_callback(struct mg_connection *nc, int ev, > > void *ev_data) > > > > > > > -- > > ===================================================================== > > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > > Phone: +49-8142-66989-53 <+49%208142%206698953> > <tel:+49%208142%206698953> Fax: > > +49-8142-66989-80 <+49%208142%206698980> <tel:+49%208142%206698980> > Email: sba...@denx.de > > ===================================================================== > > > > -- > > You received this message because you are subscribed to the Google > > Groups "swupdate" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to swupdate+u...@googlegroups.com > > <mailto:swupdate+u...@googlegroups.com>. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com > > < > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com?utm_medium=email&utm_source=footer > >. > > > -- > ===================================================================== > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: +49-8142-66989-53 <+49%208142%206698953> Fax: +49-8142-66989-80 > <+49%208142%206698980> Email: sba...@denx.de > ===================================================================== >
Hi Vincent, On 24.09.20 14:10, vincent....@gmail.com wrote: > I use SWU forwarder to send SWU files. > I think mongoose restart_handler is called by swupdate-sysrestart, and > ev_data is a null pointer so hm->method is invalid? > I cannot confirm this - I have tested myself and it is not the case. It works as expected and target reboots without any crash (current TOT). swupdate-sysrestart use a POST call, so the hm should be set. We can add a further check to the function, but then a reboot is skipped in your case. I think you should investigate which is the real cause for this. Best regards, Stefano Babic > Le jeudi 24 septembre 2020 à 13:38:06 UTC+2, Stefano Babic a écrit : > > On 24.09.20 11:52, vincent....@gmail.com wrote: > > Hi all, > > > > I have the following segfault, maybe this modification introduces it? > > Maybe not - Joshua's patch introduced a check, nothing more. You can > revert his patch, you should still have the crash. > > How do you send the SWU ? Via a browser or via self written code ? It > looks like you could send an http request with a null method. > > Best regards, > Stefano Babic > > > > > (gdb) bt > > #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, > > str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 > > #1 0x000056349213fde4 in restart_handler > (nc=nc@entry=0x563492256f30, > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at > > mongoose/mongoose_interface.c:116 > > #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, > > ev_data=ev_data@entry=0x0, > > user_data=<optimized out>) at mongoose/mongoose.c:2288 > > #3 0x000056349214d000 in mg_http_handler > (nc=nc@entry=0x563492256f30, > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 > > #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, > > ev=ev@entry=5, > > ev_data=ev_data@entry=0x0, user_data=<optimized out>) at > > mongoose/mongoose.c:2288 > > #5 0x000056349214e727 in mg_close_conn > (conn=conn@entry=0x563492256f30) > > at mongoose/mongoose.c:2395 > > #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, > > now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 > > #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, > > fd_flags=<optimized out>, nc=0x563492256f30) at > mongoose/mongoose.c:3885 > > #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized > > out>) at mongoose/mongoose.c:4116 > > #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, > > timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 > > #10 0x00005634921404e1 in start_mongoose > > (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", > > argc=argc@entry=3, argv=argv@entry=0x56349223dab8) > > at mongoose/mongoose_interface.c:615 > > #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, > > task=<optimized out>, cmdline=0x0, start=0x563492140271 > <start_mongoose>, > > av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 > "/etc/swupdate.cfg", > > run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 > > #12 start_swupdate_subprocess (type=<optimized out>, > name=0x56349216dd02 > > "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, > > argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, > > cmdline=0x0) at core/pctl.c:180 > > #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, > > name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, > > argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 > > #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at > > core/swupdate.c:938 > > > > I use swupdate with those arguments: > > > > /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f > /etc/swupdate.cfg > > -H x86-vecow v1.0.0 -p reboot > > > > Best regards, > > Vincent > > > > > > Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > > > > Hi Joshua, > > > > On 26.06.20 23:13, Joshua Watt wrote: > > > The restart_handler would crash when any non-HTTP event was > processed > > > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that > the > > > other events are ignored. > > > > > > > Correct, thanks for fix. > > > > Tested-by : Stefano Babic <sba...@denx.de> > > > > Best regards, > > Stefano Babic > > > > > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> > > > --- > > > mongoose/mongoose_interface.c | 22 +++++++++++----------- > > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > > > diff --git a/mongoose/mongoose_interface.c > > b/mongoose/mongoose_interface.c > > > index 150210e..a847cc8 100644 > > > --- a/mongoose/mongoose_interface.c > > > +++ b/mongoose/mongoose_interface.c > > > @@ -111,20 +111,20 @@ static void restart_handler(struct > > mg_connection *nc, int ev, void *ev_data) > > > struct http_message *hm = (struct http_message *) ev_data; > > > ipc_message msg = {}; > > > > > > - (void)ev; > > > + if (ev == MG_EV_HTTP_REQUEST) { > > > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > + mg_http_send_error(nc, 405, "Method Not Allowed"); > > > + return; > > > + } > > > > > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > - mg_http_send_error(nc, 405, "Method Not Allowed"); > > > - return; > > > - } > > > + int ret = ipc_postupdate(&msg); > > > + if (ret) { > > > + mg_http_send_error(nc, 500, "Failed to queue command"); > > > + return; > > > + } > > > > > > - int ret = ipc_postupdate(&msg); > > > - if (ret) { > > > - mg_http_send_error(nc, 500, "Failed to queue command"); > > > - return; > > > + mg_http_send_error(nc, 201, "Device will reboot now."); > > > } > > > - > > > - mg_http_send_error(nc, 201, "Device will reboot now."); > > > } > > > > > > static void broadcast_callback(struct mg_connection *nc, int ev, > > void *ev_data) > > > > > > > -- > > ===================================================================== > > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > > Phone: +49-8142-66989-53 <tel:+49%208142%206698953> > <tel:+49%208142%206698953> Fax: > > +49-8142-66989-80 <tel:+49%208142%206698980> > <tel:+49%208142%206698980> Email: sba...@denx.de > > ===================================================================== > > > > -- > > You received this message because you are subscribed to the Google > > Groups "swupdate" group. > > To unsubscribe from this group and stop receiving emails from it, > send > > an email to swupdate+u...@googlegroups.com > > <mailto:swupdate+u...@googlegroups.com>. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com > > > > <https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com?utm_medium=email&utm_source=footer>. > > > > -- > ===================================================================== > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: +49-8142-66989-53 <tel:+49%208142%206698953> Fax: > +49-8142-66989-80 <tel:+49%208142%206698980> Email: sba...@denx.de > ===================================================================== > > -- > You received this message because you are subscribed to the Google > Groups "swupdate" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to swupdate+unsubscribe@googlegroups.com > <mailto:swupdate+unsubscribe@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/swupdate/ca52bea0-d343-4752-bda3-bf56336d4dc7n%40googlegroups.com > <https://groups.google.com/d/msgid/swupdate/ca52bea0-d343-4752-bda3-bf56336d4dc7n%40googlegroups.com?utm_medium=email&utm_source=footer>.
OMG I'm so sorry, In fact this commit fixes my issue which is not integrated in 2020.04 (I wrongly thought it was) :x I should have check twice before, Thanks for your time and sorry again, Vincent Le jeudi 24 septembre 2020 à 16:51:37 UTC+2, Stefano Babic a écrit : > Hi Vincent, > > On 24.09.20 14:10, vincent....@gmail.com wrote: > > I use SWU forwarder to send SWU files. > > I think mongoose restart_handler is called by swupdate-sysrestart, and > > ev_data is a null pointer so hm->method is invalid? > > > > I cannot confirm this - I have tested myself and it is not the case. It > works as expected and target reboots without any crash (current TOT). > > swupdate-sysrestart use a POST call, so the hm should be set. We can add > a further check to the function, but then a reboot is skipped in your > case. I think you should investigate which is the real cause for this. > > Best regards, > Stefano Babic > > > Le jeudi 24 septembre 2020 à 13:38:06 UTC+2, Stefano Babic a écrit : > > > > On 24.09.20 11:52, vincent....@gmail.com wrote: > > > Hi all, > > > > > > I have the following segfault, maybe this modification introduces it? > > > > Maybe not - Joshua's patch introduced a check, nothing more. You can > > revert his patch, you should still have the crash. > > > > How do you send the SWU ? Via a browser or via self written code ? It > > looks like you could send an http request with a null method. > > > > Best regards, > > Stefano Babic > > > > > > > > (gdb) bt > > > #0 0x0000563492144f6a in mg_vcasecmp (str1=str1@entry=0x20, > > > str2=str2@entry=0x56349216eb96 "POST") at mongoose/mongoose.c:1563 > > > #1 0x000056349213fde4 in restart_handler > > (nc=nc@entry=0x563492256f30, > > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at > > > mongoose/mongoose_interface.c:116 > > > #2 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > > ev_handler=0x56349213fda6 <restart_handler>, ev=ev@entry=5, > > > ev_data=ev_data@entry=0x0, > > > user_data=<optimized out>) at mongoose/mongoose.c:2288 > > > #3 0x000056349214d000 in mg_http_handler > > (nc=nc@entry=0x563492256f30, > > > ev=ev@entry=5, ev_data=ev_data@entry=0x0) at mongoose/mongoose.c:6444 > > > #4 0x000056349214c1b1 in mg_call (nc=nc@entry=0x563492256f30, > > > ev_handler=0x56349214ced0 <mg_http_handler>, ev_handler@entry=0x0, > > > ev=ev@entry=5, > > > ev_data=ev_data@entry=0x0, user_data=<optimized out>) at > > > mongoose/mongoose.c:2288 > > > #5 0x000056349214e727 in mg_close_conn > > (conn=conn@entry=0x563492256f30) > > > at mongoose/mongoose.c:2395 > > > #6 0x000056349214e957 in mg_if_poll (nc=nc@entry=0x563492256f30, > > > now=now@entry=1600921606.6443131) at mongoose/mongoose.c:2330 > > > #7 0x000056349214eff6 in mg_mgr_handle_conn (now=1600921606.6443131, > > > fd_flags=<optimized out>, nc=0x563492256f30) at > > mongoose/mongoose.c:3885 > > > #8 mg_socket_if_poll (iface=<optimized out>, timeout_ms=<optimized > > > out>) at mongoose/mongoose.c:4116 > > > #9 0x0000563492146696 in mg_mgr_poll (m=m@entry=0x7fffac93f250, > > > timeout_ms=timeout_ms@entry=100) at mongoose/mongoose.c:2493 > > > #10 0x00005634921404e1 in start_mongoose > > > (cfgfname=cfgfname@entry=0x563492221ac0 "/etc/swupdate.cfg", > > > argc=argc@entry=3, argv=argv@entry=0x56349223dab8) > > > at mongoose/mongoose_interface.c:615 > > > #11 0x000056349212b2e2 in spawn_process (task=<optimized out>, > > > task=<optimized out>, cmdline=0x0, start=0x563492140271 > > <start_mongoose>, > > > av=0x56349223dab8, ac=3, cfgname=0x563492221ac0 > > "/etc/swupdate.cfg", > > > run_as_groupid=0, run_as_userid=0) at core/pctl.c:158 > > > #12 start_swupdate_subprocess (type=<optimized out>, > > name=0x56349216dd02 > > > "webserver", cfgfile=0x563492221ac0 "/etc/swupdate.cfg", argc=3, > > > argv=0x56349223dab8, start=0x563492140271 <start_mongoose>, > > > cmdline=0x0) at core/pctl.c:180 > > > #13 0x000056349212b5c9 in start_subprocess (type=<optimized out>, > > > name=<optimized out>, cfgfile=<optimized out>, argc=<optimized out>, > > > argv=<optimized out>, start=<optimized out>) at core/pctl.c:203 > > > #14 0x0000563492125404 in main (argc=12, argv=<optimized out>) at > > > core/swupdate.c:938 > > > > > > I use swupdate with those arguments: > > > > > > /usr/bin/swupdate -v -w "-r /www" -e stable copy2 -f > > /etc/swupdate.cfg > > > -H x86-vecow v1.0.0 -p reboot > > > > > > Best regards, > > > Vincent > > > > > > > > > Le dimanche 28 juin 2020 à 15:19:54 UTC+2, Stefano Babic a écrit : > > > > > > Hi Joshua, > > > > > > On 26.06.20 23:13, Joshua Watt wrote: > > > > The restart_handler would crash when any non-HTTP event was > > processed > > > > (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that > > the > > > > other events are ignored. > > > > > > > > > > Correct, thanks for fix. > > > > > > Tested-by : Stefano Babic <sba...@denx.de> > > > > > > Best regards, > > > Stefano Babic > > > > > > > Signed-off-by: Joshua Watt <JPEWh...@gmail.com> > > > > --- > > > > mongoose/mongoose_interface.c | 22 +++++++++++----------- > > > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > > > > > diff --git a/mongoose/mongoose_interface.c > > > b/mongoose/mongoose_interface.c > > > > index 150210e..a847cc8 100644 > > > > --- a/mongoose/mongoose_interface.c > > > > +++ b/mongoose/mongoose_interface.c > > > > @@ -111,20 +111,20 @@ static void restart_handler(struct > > > mg_connection *nc, int ev, void *ev_data) > > > > struct http_message *hm = (struct http_message *) ev_data; > > > > ipc_message msg = {}; > > > > > > > > - (void)ev; > > > > + if (ev == MG_EV_HTTP_REQUEST) { > > > > + if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > > + mg_http_send_error(nc, 405, "Method Not Allowed"); > > > > + return; > > > > + } > > > > > > > > - if(mg_vcasecmp(&hm->method, "POST") != 0) { > > > > - mg_http_send_error(nc, 405, "Method Not Allowed"); > > > > - return; > > > > - } > > > > + int ret = ipc_postupdate(&msg); > > > > + if (ret) { > > > > + mg_http_send_error(nc, 500, "Failed to queue command"); > > > > + return; > > > > + } > > > > > > > > - int ret = ipc_postupdate(&msg); > > > > - if (ret) { > > > > - mg_http_send_error(nc, 500, "Failed to queue command"); > > > > - return; > > > > + mg_http_send_error(nc, 201, "Device will reboot now."); > > > > } > > > > - > > > > - mg_http_send_error(nc, 201, "Device will reboot now."); > > > > } > > > > > > > > static void broadcast_callback(struct mg_connection *nc, int ev, > > > void *ev_data) > > > > > > > > > > -- > > > ===================================================================== > > > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > > > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > > > Phone: +49-8142-66989-53 <+49%208142%206698953> > <tel:+49%208142%206698953> > > <tel:+49%208142%206698953> Fax: > > > +49-8142-66989-80 <+49%208142%206698980> <tel:+49%208142%206698980> > > <tel:+49%208142%206698980> Email: sba...@denx.de > > > ===================================================================== > > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "swupdate" group. > > > To unsubscribe from this group and stop receiving emails from it, > > send > > > an email to swupdate+u...@googlegroups.com > > > <mailto:swupdate+u...@googlegroups.com>. > > > To view this discussion on the web visit > > > > > > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com > > > > > > > < > https://groups.google.com/d/msgid/swupdate/cf9ca328-f3c0-42f6-b3a4-f54036179ff9n%40googlegroups.com?utm_medium=email&utm_source=footer > >. > > > > > > > > -- > > ===================================================================== > > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > > Phone: +49-8142-66989-53 <+49%208142%206698953> > <tel:+49%208142%206698953> Fax: > > +49-8142-66989-80 <+49%208142%206698980> <tel:+49%208142%206698980> > Email: sba...@denx.de > > ===================================================================== > > > > -- > > You received this message because you are subscribed to the Google > > Groups "swupdate" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to swupdate+u...@googlegroups.com > > <mailto:swupdate+u...@googlegroups.com>. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/swupdate/ca52bea0-d343-4752-bda3-bf56336d4dc7n%40googlegroups.com > > < > https://groups.google.com/d/msgid/swupdate/ca52bea0-d343-4752-bda3-bf56336d4dc7n%40googlegroups.com?utm_medium=email&utm_source=footer > >. > > > -- > ===================================================================== > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: +49-8142-66989-53 <+49%208142%206698953> Fax: +49-8142-66989-80 > <+49%208142%206698980> Email: sba...@denx.de > ===================================================================== >
diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 150210e..a847cc8 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -111,20 +111,20 @@ static void restart_handler(struct mg_connection *nc, int ev, void *ev_data) struct http_message *hm = (struct http_message *) ev_data; ipc_message msg = {}; - (void)ev; + if (ev == MG_EV_HTTP_REQUEST) { + if(mg_vcasecmp(&hm->method, "POST") != 0) { + mg_http_send_error(nc, 405, "Method Not Allowed"); + return; + } - if(mg_vcasecmp(&hm->method, "POST") != 0) { - mg_http_send_error(nc, 405, "Method Not Allowed"); - return; - } + int ret = ipc_postupdate(&msg); + if (ret) { + mg_http_send_error(nc, 500, "Failed to queue command"); + return; + } - int ret = ipc_postupdate(&msg); - if (ret) { - mg_http_send_error(nc, 500, "Failed to queue command"); - return; + mg_http_send_error(nc, 201, "Device will reboot now."); } - - mg_http_send_error(nc, 201, "Device will reboot now."); } static void broadcast_callback(struct mg_connection *nc, int ev, void *ev_data)
The restart_handler would crash when any non-HTTP event was processed (i.e. MG_EV_CLOSE) because ev_data was NULL. Add a check so that the other events are ignored. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> --- mongoose/mongoose_interface.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)