commit 858326c0faa59d484157d59cf713b2c572e6bfa7
parent 34f30c93c7c96fba1ad860e2e6dd125b6e79d381
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Sun, 28 Feb 2021 20:45:32 -0600
remove VLA , replacing with fixed length arrays
Diffstat:
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/kiss.c b/kiss.c
@@ -50,7 +50,10 @@ kiss_download_names(char *kiss_path, char *names[], int len)
{
struct source_t sources[PKG_SOURCES_MAX];
memset(sources, 0, sizeof(sources));
- char *repo, kp[strlen(kiss_path)], path[PATH_LEN];
+ char *repo, kp[KISS_PATH_MAX], path[PATH_LEN];
+
+ if (strlen(kiss_path) >= KISS_PATH_MAX)
+ die("%s: KISS_PATH too long", __func__);
/* TODO put names in linked list to make O(n) instead of O(n^2) */
for (int i = 0; i < len; i++) {
@@ -73,8 +76,12 @@ kiss_download_names(char *kiss_path, char *names[], int len)
void
kiss_checksum_names(char *kiss_path, char *names[], int len)
{
- char *repo, kp[strlen(kiss_path)], path[PATH_LEN];
+ char *repo, kp[KISS_PATH_MAX], path[PATH_LEN];
struct source_t sources[64];
+
+ if (strlen(kiss_path) >= KISS_PATH_MAX)
+ die("%s: KISS_PATH too long", __func__);
+
for (int i = 0; i < len; i++) {
/* iterate through KISS_PATH */
memccpy(kp, kiss_path, '\0', strlen(kiss_path));
@@ -152,9 +159,12 @@ kiss_remove_names(char *names[], int len)
void
kiss_search(const char *kiss_path, char *pattern)
{
- char *repo, path[strlen(kiss_path)], pkgs[PKG_COUNT_MAX][PKG_NAME_MAX];
+ char *repo, path[KISS_PATH_MAX], pkgs[PKG_COUNT_MAX][PKG_NAME_MAX];
int pkgcount;
+ if (strlen(kiss_path) >= KISS_PATH_MAX)
+ die("%s: KISS_PATH too long", __func__);
+
memccpy(path, kiss_path, '\0', strlen(kiss_path));
if ((repo = strtok(path, ":")) == NULL)
diff --git a/util.c b/util.c
@@ -168,10 +168,13 @@ file_dropadd(char *path, char *a, char *b)
int
mkdirs(const char *path)
{
- size_t len = strlen(path);
- char dir[len];
+ int len = strlen(path);
+ char dir[PATH_LEN];
char *end = dir;
+ if (len >= PATH_LEN)
+ return -1;
+
strcpy(dir, path);
/* dir+1 to avoid removing leading /, and mkdir erroring out */
strrepl(dir+1, '/', 0);