Closed Bug 1335075 Opened 7 years ago Closed 7 years ago

RTCCertificate.cpp: output truncated before the last format character

Categories

(Core :: WebRTC, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

Details

Attachments

(1 file)

0:25.93 /root/firefox-gcc-last/dom/media/webrtc/RTCCertificate.cpp: In member function 'nsresult mozilla::dom::GenerateRTCCertificateTask::GenerateCertificate()':
 0:25.93 /root/firefox-gcc-last/dom/media/webrtc/RTCCertificate.cpp:85:12: error: output truncated before the last format character [-Werror=format-truncation=]
 0:25.93    nsresult GenerateCertificate()
 0:25.93             ^~~~~~~~~~~~~~~~~~~
 0:25.93 /root/firefox-gcc-last/dom/media/webrtc/RTCCertificate.cpp:78:15: note: format output 3 bytes into a destination of size 2
 0:25.93        snprintf(&buf[i * 2 + 3], 2, "%.2x", randomName[i]);
 0:25.93        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Should be 3:
uint8 to hexa is 2 bytes + terminating nul
Comment on attachment 8831730 [details]
Bug 1335075 - RTCCertificate.cpp: output truncated before the last format character

https://reviewboard.mozilla.org/r/108284/#review109440

This will result in a bunch of unneeded nul-byte writes... IIRC snprintf truncates the output (thus the warning), but the code follows the loop with adding a trailing nul.  I'd prefer to change it to something else that also avoids the writes, or suppress the warning.  The code is correct as-is. Can we leave it, or suppress?
In practice, the writes will tend to get whomped in the cache before hitting memory, but still...
Attachment #8831730 - Flags: review?(rjesup) → review+
backlog: --- → webrtc/webaudio+
Rank: 35
Priority: -- → P3
Randell, what about?

-      snprintf(&buf[i * 2 + 3], 2, "%.2x", randomName[i]);
+      sprintf(&buf[i * 2 + 3], "%.2x", randomName[i]);
Flags: needinfo?(rjesup)
(In reply to Sylvestre Ledru [:sylvestre] from comment #3)
> Randell, what about?
> 
> -      snprintf(&buf[i * 2 + 3], 2, "%.2x", randomName[i]);
> +      sprintf(&buf[i * 2 + 3], "%.2x", randomName[i]);

If you did that, you could remove the extra nul write at the end... but it basically has the same problem, writing many nuls and then overwriting them.  land the patch you originally gave; snprintf to make hex values isn't efficient in the first place, so it's not a big deal.
Flags: needinfo?(rjesup)
thanks!
Pushed by sledru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/369da2e22d43
RTCCertificate.cpp: output truncated before the last format character r=jesup
https://hg.mozilla.org/mozilla-central/rev/369da2e22d43
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: