<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>CoAP utils (coap_utils.h) cause stack overflow</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62356/coap-utils-coap_utils-h-cause-stack-overflow</link><description>Hi, 
 
 The situation is very simple; I try to use the CoAP Utils library to simplify CoAP usage in an application running on the nRF9160 DK ( https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/net/coap_utils.html ) 
 
 When I run</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 Jun 2020 09:19:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62356/coap-utils-coap_utils-h-cause-stack-overflow" /><item><title>RE: CoAP utils (coap_utils.h) cause stack overflow</title><link>https://devzone.nordicsemi.com/thread/254194?ContentTypeID=1</link><pubDate>Wed, 10 Jun 2020 09:19:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d96501e-4803-4ed7-84c6-1b848d1cbcd4</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;I see that R&amp;amp;D has already given an answer to your PR (&lt;a href="https://github.com/nrfconnect/sdk-nrf/pull/2451"&gt;https://github.com/nrfconnect/sdk-nrf/pull/2451&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Thanks for spotting this, we&amp;#39;ve only tested the library with Zephyr native networking stack so far, so the issue was not spotted with bsdlib.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP utils (coap_utils.h) cause stack overflow</title><link>https://devzone.nordicsemi.com/thread/254179?ContentTypeID=1</link><pubDate>Wed, 10 Jun 2020 08:49:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3d74a2f-6ad9-44fe-8bad-ddc89d8d9a0c</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi Pontus,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Happy to hear that you found the solution. Regarding if this is a bug I don&amp;#39;t know at the moment. I have forwarded your question to our R&amp;amp;D department and will get back to you within today.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP utils (coap_utils.h) cause stack overflow</title><link>https://devzone.nordicsemi.com/thread/254109?ContentTypeID=1</link><pubDate>Tue, 09 Jun 2020 20:53:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e1a47e2-3f4c-4853-9431-9447ec03968a</guid><dc:creator>Pwntus</dc:creator><description>&lt;p&gt;All the clues point me to this #define:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/subsys/net/lib/coap_utils/coap_utils.c#L20"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/subsys/net/lib/coap_utils/coap_utils.c#L20&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I manually doubled the stack size (500 &amp;gt; 1000) and&amp;nbsp;voil&amp;agrave;, it works!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know why &lt;strong&gt;500&lt;/strong&gt; is the configured size, maybe this is a bug?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: CoAP utils (coap_utils.h) cause stack overflow</title><link>https://devzone.nordicsemi.com/thread/254108?ContentTypeID=1</link><pubDate>Tue, 09 Jun 2020 20:44:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8266e5e2-5c5d-49ba-8604-2c0c84e39a04</guid><dc:creator>Pwntus</dc:creator><description>&lt;p&gt;I&amp;#39;ve traced the faulting address&amp;nbsp;&lt;strong&gt;29376&lt;/strong&gt; in build/zephyr/zephyr.lst:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static inline int nrf91_socket_offload_poll(struct pollfd *fds, int nfds,
					    int timeout)
{
   29374:	b580      	push	{r7, lr}
   29376:	b098      	sub	sp, #96	; 0x60 &amp;lt;------ here
   29378:	af00      	add	r7, sp, #0
   2937a:	60f8      	str	r0, [r7, #12]
   2937c:	60b9      	str	r1, [r7, #8]
   2937e:	607a      	str	r2, [r7, #4]
	int retval = 0;
	
	...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;...which points me to the nRF implementation of BSD sockets:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/lib/bsdlib/nrf91_sockets.c#L862"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/lib/bsdlib/nrf91_sockets.c#L862&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I do however suspect the issue is with the stack size of the current thread used by the socket, which in this case appears to be listening/polling.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thankful for any input.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>