Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[portable-snippets] Fix array length issue #35791

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ports/portable-snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(portable-snippets LANGUAGES C)
include(GNUInstallDirs)

option(PSNIP_INSTALL_HEADERS "Install header files" ON)
set(CMAKE_C_STANDARD 11)

# https://stackoverflow.com/questions/7787823/cmake-how-to-get-the-name-of-all-subdirectories-of-a-directory
function (list_subdir output_variable path)
Expand Down
89 changes: 89 additions & 0 deletions ports/portable-snippets/fix_array.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
diff --git a/random/random.c b/random/random.c
index 0a83d00..a0d628c 100644
--- a/random/random.c
+++ b/random/random.c
@@ -31,7 +31,7 @@
# endif
#endif

-static int (* psnip_random_secure_generate)(size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) = NULL;
+static int (* psnip_random_secure_generate)(size_t length, psnip_uint8_t data[]) = NULL;
static psnip_once psnip_random_secure_once = PSNIP_ONCE_INIT;

#if defined(__linux)
@@ -66,7 +66,7 @@ psnip_random__getrandom(void* buf, size_t buflen, unsigned int flags) {
# endif

static int
-psnip_random_secure_generate_getrandom(size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+psnip_random_secure_generate_getrandom(size_t length, psnip_uint8_t data[]) {
size_t bytes_read = 0;
int r;

@@ -93,7 +93,7 @@ psnip_random_secure_generate_getrandom(size_t length, psnip_uint8_t data[PSNIP_R
__attribute__((__target__("rdrnd")))
#endif
static int
-psnip_random__rdrand (size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+psnip_random__rdrand (size_t length, psnip_uint8_t data[]) {
size_t remaining = length;
unsigned int r;
#if defined(PSNIP_CPU_ARCH_X86_64)
@@ -136,7 +136,7 @@ psnip_random__rdrand (size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM
static HMODULE psnip_rand_secure__advapi32_dll = NULL;
static BOOLEAN (APIENTRY *psnip_rand_secure__RtlGenRandom)(void*, ULONG);

-static int psnip_random_secure_generate_RtlGenRandom(size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+static int psnip_random_secure_generate_RtlGenRandom(size_t length, psnip_uint8_t data[]) {
assert(psnip_rand_secure__RtlGenRandom != NULL);

return psnip_rand_secure__RtlGenRandom(data, (ULONG) length) ? 0 : -3;
@@ -162,7 +162,7 @@ psnip_random_secure_init(void) {

#if !defined(PSNIP_RANDOM_SECURE_FOUND)
static int
-psnip_random_secure_generate_dev_random(size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+psnip_random_secure_generate_dev_random(size_t length, psnip_uint8_t data[]) {
static FILE* dev_random = NULL;
size_t bytes_read = 0;

@@ -182,7 +182,7 @@ psnip_random_secure_generate_dev_random(size_t length, psnip_uint8_t data[PSNIP_
}

static int
-psnip_random_secure_generate_dev_urandom(size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+psnip_random_secure_generate_dev_urandom(size_t length, psnip_uint8_t data[]) {
static FILE* dev_urandom = NULL;
size_t bytes_read = 0;

@@ -297,7 +297,7 @@ psnip_random__pcg_from_state(psnip_uint32_t state) {
}

static int
-psnip_random__pgc_generate(psnip_atomic_int32* state, size_t length, psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+psnip_random__pgc_generate(psnip_atomic_int32* state, size_t length, psnip_uint8_t data[]) {
psnip_int32_t old_state;
psnip_uint32_t new_state, v;
size_t remaining;
@@ -369,7 +369,7 @@ psnip_random_fast_init(void) {
int
psnip_random_bytes(enum PSnipRandomSource source,
size_t length,
- psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]) {
+ psnip_uint8_t data[]) {
switch (source) {
case PSNIP_RANDOM_SOURCE_SECURE:
#if !defined(PSNIP_RANDOM_SECURE_NO_INIT)
diff --git a/random/random.h b/random/random.h
index 4d654cc..3786921 100644
--- a/random/random.h
+++ b/random/random.h
@@ -27,7 +27,7 @@ enum PSnipRandomSource {

int psnip_random_bytes (enum PSnipRandomSource source,
size_t length,
- psnip_uint8_t data[PSNIP_RANDOM_ARRAY_PARAM(length)]);
+ psnip_uint8_t data[]);
psnip_uint32_t psnip_random_get_seed (void);
void psnip_random_set_seed (psnip_uint32_t seed);

2 changes: 2 additions & 0 deletions ports/portable-snippets/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ vcpkg_from_github(
REF 26496acb37ab46ee249ea19d45381da6955d89c4
SHA512 6213b22e4358b06f92396731d94fd27d4cf3568a47c56c057174c1839929c6a569ad5b1e1302fe0d092c4f393c570607b96e9e977223f86a9e3c2862010f3af0
HEAD_REF master
PATCHES
fix_array.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
Expand Down
2 changes: 1 addition & 1 deletion ports/portable-snippets/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "portable-snippets",
"version-date": "2019-09-20",
"port-version": 3,
"port-version": 4,
"description": "Collection of miscellaneous portable C snippets",
"homepage": "https://github.com/nemequ/portable-snippets",
"license": null,
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6730,7 +6730,7 @@
},
"portable-snippets": {
"baseline": "2019-09-20",
"port-version": 3
"port-version": 4
},
"portaudio": {
"baseline": "19.7",
Expand Down
5 changes: 5 additions & 0 deletions versions/p-/portable-snippets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "48afab31a20c7a30b01e5b1875e5b9ef0b7ededf",
"version-date": "2019-09-20",
"port-version": 4
},
{
"git-tree": "cb5584d76235e5a975e7c201d244c385cfd1dae7",
"version-date": "2019-09-20",
Expand Down