espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.87k stars 7.32k forks source link

mdns_example.c panic / crash #1591

Closed brannan closed 6 years ago

brannan commented 6 years ago

mdns_result_t TXT values may have a key and no value. Here is an excerpt of what is generated on my system by one of our printers the the second format specifier in line 140 is changed from %s to %p: .... TXT : [15] txtvers=0x3ffbaa5c; note=0x0; rp=0x3ffbac98; qtotal=0x3ffc7460; priority=0x3ffbacc0; ty=0x3ffbacd0; product=0x3ffbacf8; pdl=0x3ffbad1c; adminurl=0x3ffbb50c; usb_MFG=0x3ffbb534; usb_MDL=0x3ffbb54c; UUID=0x3ffbb56c; Transparent=0x3ffbb5a8; Binary=0x3ffbb5bc; TBCP=0x3ffbb5d0; ....

Look at the second entry, "note." The value is NULL.

A simple fix on line 140 alone:

printf("%s=%s; ", r->txt[t].key, r->txt[t].value);

to:

printf("%s=%p; ", r->txt[t].key, r->txt[t].value);

The %p format specifier allows for NULL. The %s format specifier does not. A slightly more user-friendly fix would be:

if (r->txt[t].value) { printf("%s=%s; ", r->txt[t].key, r->txt[t].value); } else { printf("%s=%p; ", r->txt[t].key, r->txt[t].value); }

If you do that then you get output like this instead of just addresses:

TXT : [26] txtvers=1; note=0x0; rp=ipp/print; qtotal=1; priority=40; ty=Xerox WorkCentre 6515DN; product=(Xerox WorkCentre 6515); pdl=application/octet-stream,image/urf,image/pwg-raster,image/jpeg,application/pdf; adminurl=http://XC6e1ff8.local/; usb_MFG=Xerox; usb_MDL=WorkCentre 6515; UUID=fe55c9a0-1dd1-11b2-92e7-9c934e6e1ff8; TLS=1.2; Transparent=T; Binary=T; TBCP=F; wfds-print=T; mopria-certified=1.3; URF=IS4-20,IFU20,OB10,CP255,DM1,MT1,PQ4-5,RS600,W8,SRGB24,V1.4,FN3; Color=T; Duplex=T; Fax=T; Scan=T; kind=document,envelope,label; PaperMax=legal-A4; rfo=ipp/faxout;

me-no-dev commented 6 years ago

Fixed in https://github.com/espressif/esp-idf/commit/be707f1c6b0a196489c98508f203abe6a0ca21e2#diff-4890ea78502ed51b9f2c51994cd6a2e5 😄