Skip to content

Commit fabf4cd

Browse files
committed
Use calloc for sshkeys if mmap is not supported.
Based on Github PR#597 from Mike Frysinger, any bugs added by me.
1 parent 9f0dd95 commit fabf4cd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ AC_CHECK_HEADERS([ \
536536
nlist.h \
537537
poll.h \
538538
stdint.h \
539+
sys/mmap.h \
539540
sys/stat.h \
540541
sys/time.h \
541542
sys/un.h \
@@ -2103,6 +2104,7 @@ AC_CHECK_FUNCS([ \
21032104
memmove \
21042105
memset_s \
21052106
mkdtemp \
2107+
mmap \
21062108
ngetaddrinfo \
21072109
nlist \
21082110
nsleep \

sshkey.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ sshkey_sk_cleanup(struct sshkey *k)
723723
static int
724724
sshkey_prekey_alloc(u_char **prekeyp, size_t len)
725725
{
726+
#if defined(HAVE_MMAP) && defined(MAP_ANON) && defined(MAP_PRIVATE)
726727
u_char *prekey;
727728

728729
*prekeyp = NULL;
@@ -734,14 +735,21 @@ sshkey_prekey_alloc(u_char **prekeyp, size_t len)
734735
#endif
735736
*prekeyp = prekey;
736737
return 0;
738+
#else
739+
*prekeyp = calloc(1, len);
740+
#endif /* HAVE_MMAP et al */
737741
}
738742

739743
static void
740744
sshkey_prekey_free(void *prekey, size_t len)
741745
{
746+
#if defined(HAVE_MMAP) && defined(MAP_ANON) && defined(MAP_PRIVATE)
742747
if (prekey == NULL)
743748
return;
744749
munmap(prekey, len);
750+
#else
751+
free(prekey);
752+
#endif /* HAVE_MMAP et al */
745753
}
746754

747755
static void

0 commit comments

Comments
 (0)