aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-10-23 23:04:03 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-10-23 23:07:57 +0300
commit041274604961bc5633c70f9c3db90f46117c508e (patch)
tree0e583c467fab385c213cfe3dfe7197b8ae4cb4d9
parentf9161110952dd0c6dbf431b2e4e0064b09876e30 (diff)
downloadck-041274604961bc5633c70f9c3db90f46117c508e.tar.gz
ck-041274604961bc5633c70f9c3db90f46117c508e.tar.bz2
ck-041274604961bc5633c70f9c3db90f46117c508e.zip
Secure ckutil functions
-rw-r--r--src/ckutil.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ckutil.c b/src/ckutil.c
index 272f737..6ce736c 100644
--- a/src/ckutil.c
+++ b/src/ckutil.c
@@ -20,6 +20,9 @@
#include "ckutil.h"
int util_is_dir(const char *path) {
+ if (!path) {
+ return 0;
+ }
DIR *dir;
dir = opendir(path);
if (!dir) {
@@ -30,6 +33,9 @@ int util_is_dir(const char *path) {
}
void util_replace_slash_with_uscore(char *s) {
+ if (!s) {
+ return;
+ }
int i = 0;
while (*s != '\0') {
if (*s == '/' && i != 0) {
@@ -41,6 +47,9 @@ void util_replace_slash_with_uscore(char *s) {
}
int util_file_exists(const char* path, char *absPath) {
+ if (!path || !absPath) {
+ return 0;
+ }
struct stat st = {0};
if (stat(path, &st) == -1) {
return 0;
@@ -52,6 +61,9 @@ int util_file_exists(const char* path, char *absPath) {
}
int util_is_file_rw(const char *path) {
+ if (!path) {
+ return 0;
+ }
if (access(path, R_OK | W_OK) == 0) {
return 1;
}
@@ -59,6 +71,9 @@ int util_is_file_rw(const char *path) {
}
int util_is_file_link(const char *path) {
+ if (!path) {
+ return 0;
+ }
struct stat buf;
lstat(path, &buf);
if (S_ISLNK(buf.st_mode)) {
@@ -68,10 +83,16 @@ int util_is_file_link(const char *path) {
}
void util_mkdir(const char *name) {
+ if (!name) {
+ return;
+ }
mkdir(name, 0755);
}
int util_move_file(const char *path, const char* dest) {
+ if (!path || !dest) {
+ return 0;
+ }
int srcFile = open(path, O_RDONLY);
int destFile = open(dest, O_WRONLY | O_CREAT);
struct stat st, newSt;
@@ -93,11 +114,17 @@ int util_move_file(const char *path, const char* dest) {
}
int util_symlink_file(const char *path, const char* dest) {
+ if (!path || !dest) {
+ return -1;
+ }
return symlink(path, dest);
}
void str_make_ck_config_name(char *ret, const char *path,
const char *progName) {
+ if (!path || !ret || !progName) {
+ return;
+ }
char *basec = strdup(path);
char *bname = basename(basec);
@@ -107,6 +134,9 @@ void str_make_ck_config_name(char *ret, const char *path,
void str_join_dirname_with_basename(char *ret, const char *dirname,
const char *basename) {
+ if (!dirname || !ret || !basename) {
+ return;
+ }
strcpy(ret, dirname);
strcat(ret, "/");
strcat(ret, basename);