Skip to content

Commit 8d590a1

Browse files
schwabecron2
authored andcommitted
Make get_random return int64 instead of long
This avoids having get_ranomd being different on 32bit/Windows vs 64 bit Unix platform. Also adjust platform_create_temp_file to create the same files on all platforms. Change-Id: Ifefb3ad204c0c16cb4952dd6e8661fdc9136b125 Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1732 Message-Id: <20260626152951.29207-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg37322.html Signed-off-by: Gert Doering <gert@greenie.muc.de> (cherry picked from commit 712f3d6) (cherry picked from commit bab5ee2)
1 parent 477775b commit 8d590a1

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/openvpn/crypto.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,12 @@ prng_bytes(uint8_t *output, int len)
17741774
}
17751775
}
17761776

1777-
/* an analogue to the random() function, but use prng_bytes */
1778-
long int
1777+
/* an analogue to the random() function, but use prng_bytes and
1778+
* also int64_t instead of long to avoid LLP64 vs LP64 */
1779+
int64_t
17791780
get_random(void)
17801781
{
1781-
long int l;
1782+
int64_t l;
17821783
prng_bytes((unsigned char *)&l, sizeof(l));
17831784
if (l < 0)
17841785
{

src/openvpn/crypto.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,13 @@ void prng_bytes(uint8_t *output, int len);
491491

492492
void prng_uninit(void);
493493

494-
/* an analogue to the random() function, but use prng_bytes */
495-
long int get_random(void);
494+
/**
495+
* an analogue to the random() function, but use prng_bytes and
496+
* also int64_t instead of long to avoid LLP64 vs LP64
497+
*
498+
* @return Returns a random positive 63 bit integer
499+
*/
500+
int64_t get_random(void);
496501

497502
/** Print a cipher list entry */
498503
void print_cipher(const cipher_kt_t *cipher);

src/openvpn/platform.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,15 @@ platform_create_temp_file(const char *directory, const char *prefix, struct gc_a
345345
const char *retfname = NULL;
346346
unsigned int attempts = 0;
347347
char fname[256] = { 0 };
348-
const char *fname_fmt = PACKAGE "_%.*s_%08lx%08lx.tmp";
348+
const char *fname_fmt = PACKAGE "_%.*s_%08" PRIx64 "%08" PRIx64 ".tmp";
349349
const int max_prefix_len = sizeof(fname) - (sizeof(PACKAGE) + 7 + (2 * 8));
350350

351351
while (attempts < 6)
352352
{
353353
++attempts;
354354

355355
if (!openvpn_snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len,
356-
prefix, (unsigned long) get_random(),
357-
(unsigned long) get_random()))
356+
prefix, get_random(), get_random()))
358357
{
359358
msg(M_WARN, "ERROR: temporary filename too long");
360359
return NULL;

0 commit comments

Comments
 (0)