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

Minor fixes #112

Merged
merged 8 commits into from
Sep 27, 2024
Merged
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
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ DBGFLAGS = -g -fsanitize=address

# set local lib to lib/*/*.a
LOCAL_LIBS = $(wildcard lib/*/*.a)
LIBS = ${LOCAL_LIBS} -lcurl -lsqlite3 -lm -lcrypto
LIBS = ${LOCAL_LIBS} -lcurl -lm -lcrypto

# change these to proper directories where each file should be
SRCDIR = src
Expand Down
2 changes: 1 addition & 1 deletion src/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

int result = 0;

char** cleanup_loc;

Check warning on line 24 in src/clean.c

View workflow job for this annotation

GitHub Actions / c-linter

src/clean.c:24:12 [cppcoreguidelines-init-variables]

variable 'cleanup_loc' is not initialized
msg(WARNING, "This will delete: %s", cleanups);
int count = splita(cleanups, ':', &cleanup_loc);

Expand All @@ -30,7 +30,7 @@
struct stat st;
if (lstat(cleanup_loc[i], &st) != 0)
{
msg(ERROR,"Error getting file info\n");
dbg(2, "Error getting file info");
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>

#include <curl/curl.h>

Check failure on line 6 in src/download.c

View workflow job for this annotation

GitHub Actions / c-linter

src/download.c:6:10 [clang-diagnostic-error]

'curl/curl.h' file not found

// Include necessary headers

Expand All @@ -17,6 +17,7 @@
if(curl)
{
CURLcode res;
curl_easy_setopt(curl, CURLOPT_USERAGENT, "CCCP/1.0 (https://www.sovietlinux.org/)");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
Expand Down
6 changes: 2 additions & 4 deletions src/install.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _GNU_SOURCE

Check warning on line 1 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:1:9 [bugprone-reserved-identifier]

declaration uses identifier '_GNU_SOURCE', which is a reserved identifier

#include <stdio.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -40,7 +40,7 @@
- 0: Package installed successfully.
- -1: Installation failed.
*/
int f_install_package_source(const char* spm_path, int as_dep, char* repo) {

Check warning on line 43 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:43:5 [readability-function-cognitive-complexity]

function 'f_install_package_source' has cognitive complexity of 61 (threshold 25)
// Check if spm_path is NULL

if (spm_path == NULL) {
Expand Down Expand Up @@ -82,25 +82,25 @@
{
dbg(1, "Getting environment variables...");
char* env_path = calloc(MAX_PATH, 1);
sprintf(env_path, "%s/%s", getenv("SOVIET_ENV_DIR"), pkg.environment);

Check warning on line 85 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:85:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11

readConfig(env_path, 1);
}

// Set global environment variables

if (pkg.exports != NULL && pkg.exportsCount > 0 && strlen(pkg.exports[0]) > 0)

Check warning on line 92 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:92:9 [clang-analyzer-unix.Malloc]

Potential leak of memory pointed to by 'env_path'
{
dbg(1, "Setting environment variables...");
char* env_path = calloc(MAX_PATH, 1);
sprintf(env_path, "%s/%s", getenv("SOVIET_ENV_DIR"), pkg.name);

Check warning on line 96 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:96:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11

FILE *env_file;

Check warning on line 98 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:98:15 [cppcoreguidelines-init-variables]

variable 'env_file' is not initialized
env_file = fopen(env_path, "w");

Check warning on line 99 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:99:18 [clang-analyzer-unix.Malloc]

Potential leak of memory pointed to by 'env_path'

for (int i = 0; i < pkg.exportsCount; i++)
{
fprintf(env_file, "%s \n", pkg.exports[i]);
fprintf(env_file, "%s\n", pkg.exports[i]);

if((pkg.exports[i][0] != '#' || (pkg.exports[i][0] != '/' && pkg.exports[i][1] != '/')) && strstr(pkg.exports[i], "=") != 0)
{
Expand All @@ -115,7 +115,7 @@
dbg(2, "Key: %s Value: %s", key, value);

// Set environment variables based on the key-value pairs in the config file
setenv(key, value, 1);

Check warning on line 118 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:118:17 [clang-analyzer-core.NonNullParamChecker]

Null pointer passed to 2nd parameter expecting 'nonnull'
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@


// Check if a package is a collection
if(strcmp(pkg.type, "con") != 0)

Check warning on line 163 in src/install.c

View workflow job for this annotation

GitHub Actions / c-linter

src/install.c:163:8 [clang-analyzer-core.NonNullParamChecker]

Null pointer passed to 1st parameter expecting 'nonnull'
{
// Legacy directory path for compatibility
char legacy_dir[MAX_PATH];
Expand Down Expand Up @@ -483,9 +483,7 @@
free(pkg->optional);
}
if (pkg->files) {
for (int i = 0; i < pkg->filesCount; i++) {
if (pkg->files[i] != NULL) free(pkg->files[i]);
}
if (*pkg->files) free(*pkg->files);
free(pkg->files);
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ char ** search(char *term, int *num_results) {

if (files_array != NULL) {
// Print each file path
for (int i = 0; i < num_files-1; i++)
for (int i = 0; i < num_files; i++)
{

// This will break if the files are not separated into repos
Expand Down
6 changes: 3 additions & 3 deletions src/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ int make(char* package_dir, struct package* pkg) {

SHA256((unsigned char*) buffer, size, hash);

if (hash[0] == 0) {
msg(FATAL, "Could not verify the file's hash");
return -1;
if (hash == NULL) {
msg(FATAL, "Could not verify the file's hash");
return -1;
}

dbg(1, "Hash is %s", file_sha256);
Expand Down
2 changes: 1 addition & 1 deletion src/uninstall.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int uninstall(char* name)

//dbg(3, "Removing %s", loc_path);
if (rmany(loc_path) != 0) {
msg(FATAL,"Failed to remove %s",loc_path);
msg(ERROR,"Failed to remove %s",loc_path);
perror("remove");
}
}
Expand Down
Loading