On Sun, Apr 19, 2020 at 05:35:50PM -0400, Remco Rijnders wrote:
+/* Return a Base64 encoded representation of a 64 bit random number */
+char *mutt_gen_base64_enc_rand (void)
+{
+ unsigned char rbuf[8];
+ unsigned char result[12];
+ uint64_t r = 0;
+
+ r = rand_uint64();
+
+ rbuf[0] = r & 0xFF;
+ rbuf[1] = (r >> 8) & 0xFF;
+ rbuf[2] = (r >> 16) & 0xFF;
+ rbuf[3] = (r >> 24) & 0xFF;
+ rbuf[4] = (r >> 32) & 0xFF;
+ rbuf[5] = (r >> 40) & 0xFF;
+ rbuf[6] = (r >> 48) & 0xFF;
+ rbuf[7] = (r >> 56) & 0xFF;
+
just use memcpy(). endianess doesn't matter.
+ mutt_to_base64(result, rbuf, 8, 12);
+ result[11] = '\0'; /* The padded '=' at the end adds no value to our result
*/
+
+ return (safe_strdup ((char*)result));
+}
+
char *mutt_gen_msgid (void)
{
char buf[SHORT_STRING];
if (!(fqdn = mutt_fqdn(0)))
fqdn = NONULL(Hostname);
+ snprintf (buf, sizeof (buf), "<%s.%s@%s>",
mutt_gen_base64_enc_rand(), + mutt_gen_base64_enc_rand(), fqdn);
you're leaking the random strings. i suggest passing in fixed-size
buffers instead.
return (safe_strdup (buf));
}