Skip to content

Commit

Permalink
Solaris getrandom apparently cannot cope with a parameter of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
david-dick committed Feb 8, 2025
1 parent b2b6f6f commit e7f8d60
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions URandom.xs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ crypt_urandom_getrandom(length)
int result;
CODE:
Newx(data, length + 1u, char);
#if defined(__sun) && defined(__SVR4)
if (length == 0) {
result = 0;
} else {
#endif
GETRANDOM:
#ifdef HAVE_CRYPT_URANDOM_NATIVE_GETRANDOM
result = getrandom(data, length, GRND_NONBLOCK);
Expand Down Expand Up @@ -72,6 +77,9 @@ crypt_urandom_getrandom(length)
croak("Failed to getrandom:%s", strerror(errno));
}
}
#if defined(__sun) && defined(__SVR4)
}
#endif
data[result] = '\0';
RETVAL = newSVpv(data, result);
Safefree(data);
Expand Down

0 comments on commit e7f8d60

Please sign in to comment.