diff --git a/cli/src/basic.c b/cli/src/basic.c index 37ca120..d4de536 100644 --- a/cli/src/basic.c +++ b/cli/src/basic.c @@ -4,18 +4,14 @@ */ #include "basic.h" #include -#include "logger.h" +#include void InitParsedConfig(struct ParsedConfig *parsedConfig) { -<<<<<<< HEAD - if (parsedConfig != NULL) { -======= - if (parsedConfig != NULL) - { ->>>>>>> fd706c08945c4519bcefe0d295d55c42c7ad1711 - Logger("parsedConfig Pointer is null!."); + if (parsedConfig == NULL) { + fprintf(stderr, "parsedConfig pointer is null!\n"); return; } + parsedConfig->devicesNr = MAX_DEVICE_NR; } \ No newline at end of file diff --git a/cli/src/cgrp.c b/cli/src/cgrp.c index 29534bc..83b5864 100644 --- a/cli/src/cgrp.c +++ b/cli/src/cgrp.c @@ -21,6 +21,11 @@ bool TakeNthWord(char **pLine, unsigned int n, char **word) { + if (pLine == NULL || word == NULL) { + fprintf(stderr, "pLine, word pointer is null!\n"); + return false; + } + char *w = NULL; for (unsigned int i = 0; i < n; i++) { w = strsep(pLine, " "); @@ -35,6 +40,11 @@ bool TakeNthWord(char **pLine, unsigned int n, char **word) bool CheckRootDir(char **pLine) { + if (pLine == NULL) { + fprintf(stderr, "pLine pointer is null!\n"); + return false; + } + char *rootDir = NULL; if (!TakeNthWord(pLine, ROOT_GAP, &rootDir)) { return false; @@ -45,6 +55,11 @@ bool CheckRootDir(char **pLine) bool CheckFsType(char **pLine) { + if (pLine == NULL) { + fprintf(stderr, "pLine pointer is null!\n"); + return false; + } + char* fsType = NULL; if (!TakeNthWord(pLine, FSTYPE_GAP, &fsType)) { return false; @@ -55,6 +70,11 @@ bool CheckFsType(char **pLine) bool CheckSubStr(char **pLine, const char *subsys) { + if (pLine == NULL || subsys == NULL) { + fprintf(stderr, "pLine, subsys pointer is null!\n"); + return false; + } + char* substr = NULL; if (!TakeNthWord(pLine, MOUNT_SUBSTR_GAP, &substr)) { return false; @@ -66,6 +86,11 @@ bool CheckSubStr(char **pLine, const char *subsys) typedef char *(*ParseFileLine)(char *, const char *); int ParseFileByLine(char* buffer, int bufferSize, const ParseFileLine fn, const char* filepath) { + if (buffer == NULL || filepath == NULL) { + fprintf(stderr, "buffer, filepath pointer is null!\n"); + return -1; + } + FILE *fp = NULL; char *result = NULL; char *line = NULL; @@ -107,6 +132,11 @@ int ParseFileByLine(char* buffer, int bufferSize, const ParseFileLine fn, const char *GetCgroupMount(char *line, const char *subsys) { + if (line == NULL || subsys == NULL) { + fprintf(stderr, "line, subsys pointer is null!\n"); + return NULL; + } + if (!CheckRootDir(&line)) { return NULL; } @@ -131,6 +161,11 @@ char *GetCgroupMount(char *line, const char *subsys) char *GetCgroupRoot(char *line, const char *subSystem) { + if (line == NULL || subSystem == NULL) { + fprintf(stderr, "line, subSystem pointer is null!\n"); + return NULL; + } + char *token = NULL; int i; for (i = 0; i < ROOT_SUBSTR_GAP; ++i) { @@ -156,6 +191,11 @@ char *GetCgroupRoot(char *line, const char *subSystem) int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName) { + if (cgroupAllow == NULL || devName == NULL) { + fprintf(stderr, "cgroupAllow, devName pointer is null!\n"); + return -1; + } + int ret; struct stat devStat; char devPath[BUF_SIZE]; @@ -188,8 +228,12 @@ int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName) int SetupDriverCgroup(FILE *cgroupAllow) { - int ret; + if (cgroupAllow == NULL) { + fprintf(stderr, "cgroupAllow pointer is null!\n"); + return -1; + } + int ret; ret = SetupDeviceCgroup(cgroupAllow, DAVINCI_MANAGER); if (ret < 0) { char* str = FormatLogMessage("failed to setup cgroup for %s.", DAVINCI_MANAGER); @@ -219,6 +263,11 @@ int SetupDriverCgroup(FILE *cgroupAllow) int GetCgroupPath(int pid, char *effPath, size_t maxSize) { + if (effPath == NULL) { + fprintf(stderr, "effPath pointer is null!\n"); + return -1; + } + int ret; char mountPath[BUF_SIZE] = {0x0}; char mount[BUF_SIZE] = {0x0}; @@ -267,12 +316,15 @@ int GetCgroupPath(int pid, char *effPath, size_t maxSize) int SetupCgroup(const struct ParsedConfig *config) { - int ret; + if (config == NULL) { + fprintf(stderr, "config pointer is null!\n"); + return -1; + } + char *str = NULL; char deviceName[BUF_SIZE] = {0}; char resolvedCgroupPath[PATH_MAX] = {0}; FILE *cgroupAllow = NULL; - if (realpath(config->cgroupPath, resolvedCgroupPath) == NULL && errno != ENOENT) { Logger("cannot canonicalize cgroup.", LEVEL_ERROR, SCREEN_YES); free(str); @@ -289,26 +341,23 @@ int SetupCgroup(const struct ParsedConfig *config) return -1; } - ret = SetupDriverCgroup(cgroupAllow); - if (ret < 0) { + if (SetupDriverCgroup(cgroupAllow) < 0) { fclose(cgroupAllow); Logger("failed to setup driver cgroup.", LEVEL_ERROR, SCREEN_YES); return -1; } - for (size_t idx = 0; idx < config->devicesNr; idx++) { - int ret = sprintf_s(deviceName, BUF_SIZE, "%s%u", + if (sprintf_s(deviceName, BUF_SIZE, "%s%u", (IsVirtual() ? VDEVICE_NAME : DEVICE_NAME), - config->devices[idx]); - if (ret < 0) { + config->devices[idx]) < 0) { fclose(cgroupAllow); str = FormatLogMessage("failed to assemble device path for no.%u.", config->devices[idx]); Logger(str, LEVEL_ERROR, SCREEN_YES); free(str); return -1; } - ret = SetupDeviceCgroup(cgroupAllow, (const char *)deviceName); - if (ret < 0) { + + if (SetupDeviceCgroup(cgroupAllow, (const char *)deviceName) < 0) { fclose(cgroupAllow); Logger("failed to setup cgroup.", LEVEL_ERROR, SCREEN_YES); free(str); diff --git a/cli/src/logger.c b/cli/src/logger.c index 6745515..4445c78 100644 --- a/cli/src/logger.c +++ b/cli/src/logger.c @@ -22,6 +22,11 @@ int GetCurrentLocalTime(char* buffer, int length) { + if (buffer == NULL) { + fprintf(stderr, "buffer pointer is null!\n"); + return -1; + } + time_t timep = time(NULL); struct tm result = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; struct tm *timeinfo = localtime_r(&timep, &result); @@ -56,6 +61,11 @@ int CreateLog(const char* filename) long GetLogSize(const char* filename) { + if (filename == NULL) { + fprintf(stderr, "filename pointer is null!\n"); + return -1; + } + int ret; ret = CreateLog(filename); if (ret < 0) { @@ -85,6 +95,11 @@ long GetLogSize(const char* filename) int LogLoop(const char* filename) { + if (filename == NULL) { + fprintf(stderr, "filename pointer is null!\n"); + return -1; + } + int ret; char* loopPath = LOG_PATH_DIR"docker-runtime-log.log.1"; int exist; @@ -105,6 +120,11 @@ int LogLoop(const char* filename) void WriteLogFile(const char* filename, long maxSize, const char* buffer, unsigned bufferSize) { + if (filename == NULL || buffer == NULL) { + fprintf(stderr, "filename, buffer pointer is null!\n"); + return; + } + if (filename != NULL && buffer != NULL) { char path[PATH_MAX + 1] = {0x00}; FILE *fp = NULL; diff --git a/cli/src/main.c b/cli/src/main.c index ac7c06d..5319d83 100644 --- a/cli/src/main.c +++ b/cli/src/main.c @@ -47,6 +47,11 @@ typedef bool (*CmdArgParser)(struct CmdArgs *args, const char *arg); static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + errno_t err = strcpy_s(args->devices, BUF_SIZE, arg); if (err != EOK) { Logger("failed to get devices from cmd args.", LEVEL_ERROR, SCREEN_YES); @@ -58,6 +63,11 @@ static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg) static bool PidCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + errno = 0; args->pid = strtol(optarg, NULL, DECIMAL); if (errno != 0) { @@ -79,6 +89,11 @@ static bool PidCmdArgParser(struct CmdArgs *args, const char *arg) static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + errno_t err = strcpy_s(args->rootfs, BUF_SIZE, arg); if (err != EOK) { Logger("failed to get rootfs path from cmd args", LEVEL_ERROR, SCREEN_YES); @@ -90,6 +105,11 @@ static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg) static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + errno_t err = strcpy_s(args->options, BUF_SIZE, arg); if (err != EOK) { Logger("failed to get options string from cmd args", LEVEL_ERROR, SCREEN_YES); @@ -101,6 +121,11 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg) static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + if (args->files.count == MAX_MOUNT_NR) { char* str = FormatLogMessage("too many files to mount, max number is %u", MAX_MOUNT_NR); Logger(str, LEVEL_ERROR, SCREEN_YES); @@ -122,6 +147,11 @@ static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg) static bool MountDirCmdArgParser(struct CmdArgs *args, const char *arg) { + if (args == NULL || arg == NULL) { + fprintf(stderr, "args, arg pointer is null!\n"); + return false; + } + if (args->dirs.count == MAX_MOUNT_NR) { char* str = FormatLogMessage("too many directories to mount, max number is %u", MAX_MOUNT_NR); Logger(str, LEVEL_ERROR, SCREEN_YES); @@ -157,6 +187,11 @@ static struct { static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value) { + if (args == NULL || value == NULL) { + fprintf(stderr, "args, value pointer is null!\n"); + return -1; + } + int i; for (i = 0; i < NUM_OF_CMD_ARGS; i++) { if (g_cmdArgParsers[i].c == indicator) { @@ -182,11 +217,20 @@ static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *valu static inline bool IsCmdArgsValid(const struct CmdArgs *args) { + if (args == NULL) { + fprintf(stderr, "args pointer is null!\n"); + return false; + } return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0); } static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *devices) { + if (idList == NULL || idListSize == NULL || devices == NULL) { + fprintf(stderr, "idList, idListSize, devices pointer is null!\n"); + return -1; + } + static const char *sep = ","; char *token = NULL; char *context = NULL; @@ -220,6 +264,11 @@ static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *device int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config) { + if (args == NULL || config == NULL) { + fprintf(stderr, "args, config pointer is null!\n"); + return -1; + } + int ret; errno_t err; @@ -272,6 +321,11 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config) int SetupContainer(struct CmdArgs *args) { + if (args == NULL) { + fprintf(stderr, "args pointer is null!\n"); + return -1; + } + int ret; struct ParsedConfig config; @@ -324,6 +378,10 @@ int SetupContainer(struct CmdArgs *args) int Process(int argc, char **argv) { + if (argv == NULL) { + fprintf(stderr, "argv pointer is null!\n"); + return -1; + } int c; int ret; int optionIndex; diff --git a/cli/src/options.c b/cli/src/options.c index 144e3d3..2300016 100644 --- a/cli/src/options.c +++ b/cli/src/options.c @@ -24,6 +24,11 @@ static struct { void ParseRuntimeOptions(const char *options) { + if (options == NULL) { + fprintf(stderr, "options pointer is null!\n"); + return; + } + // set defaults value g_runtimeOptions.noDrv = false; g_runtimeOptions.isVirtual = false; diff --git a/cli/src/u_mount.c b/cli/src/u_mount.c index a54f08f..129f540 100644 --- a/cli/src/u_mount.c +++ b/cli/src/u_mount.c @@ -18,6 +18,11 @@ int Mount(const char *src, const char *dst) { + if (src == NULL || dst == NULL) { + fprintf(stderr, "src pointer or dst pointer is null!\n"); + return -1; + } + static const unsigned long mountFlags = MS_BIND; static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID; int ret; @@ -44,6 +49,11 @@ int Mount(const char *src, const char *dst) static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName, struct PathInfo* pathInfo) { + if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL || pathInfo == NULL) { + fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName, pathInfo pointer are null!\n"); + return -1; + } + int ret; errno_t err; char unresolvedDst[BUF_SIZE] = {0}; @@ -96,21 +106,23 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName, int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName) { - int ret; + if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL) { + fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName pointer is null!\n"); + return -1; + } + char *str = NULL; char src[BUF_SIZE] = {0}; char dst[BUF_SIZE] = {0}; struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE}; - ret = GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo); - if (ret < 0) { + if (GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo) < 0) { str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName); Logger(str, LEVEL_ERROR, SCREEN_YES); free(str); return -1; } struct stat srcStat; - ret = stat((const char *)src, &srcStat); - if (ret < 0) { + if (stat((const char *)src, &srcStat) < 0) { str = FormatLogMessage("failed to stat src: %s.", src); Logger(str, LEVEL_ERROR, SCREEN_YES); free(str); @@ -118,6 +130,7 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe } errno = 0; struct stat dstStat; + int ret; ret = stat((const char *)dst, &dstStat); if (ret == 0 && S_ISCHR(dstStat.st_mode)) { return 0; // 特权容器自动挂载HOST所有设备,故此处跳过 @@ -130,15 +143,15 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES); return -1; } - ret = MakeMountPoints(dst, srcStat.st_mode); - if (ret < 0) { + + if (MakeMountPoints(dst, srcStat.st_mode) < 0) { str = FormatLogMessage("failed to create mount dst file: %s.", dst); Logger(str, LEVEL_ERROR, SCREEN_YES); free(str); return -1; } - ret = Mount(src, dst); - if (ret < 0) { + + if (Mount(src, dst) < 0) { Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES); return -1; } @@ -148,6 +161,11 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned int ids[], size_t idsNr) { + if (rootfs == NULL || device_name == NULL) { + fprintf(stderr, "rootfs, device_name pointer is null!\n"); + return -1; + } + char srcDeviceName[BUF_SIZE] = {0}; char dstDeviceName[BUF_SIZE] = {0}; @@ -174,6 +192,11 @@ int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned int MountFile(const char *rootfs, const char *filepath) { + if (rootfs == NULL || filepath == NULL) { + fprintf(stderr, "rootfs, filepath pointer is null!\n"); + return -1; + } + int ret; char dst[BUF_SIZE] = {0}; @@ -210,6 +233,11 @@ int MountFile(const char *rootfs, const char *filepath) int MountDir(const char *rootfs, const char *src) { + if (rootfs == NULL || src == NULL) { + fprintf(stderr, "rootfs, src pointer is null!\n"); + return -1; + } + int ret; char dst[BUF_SIZE] = {0}; @@ -245,6 +273,11 @@ int MountDir(const char *rootfs, const char *src) int DoCtrlDeviceMounting(const char *rootfs) { + if (rootfs == NULL) { + fprintf(stderr, "rootfs pointer is null!\n"); + return -1; + } + /* device */ int ret = MountDevice(rootfs, DAVINCI_MANAGER, NULL); if (ret < 0) { @@ -275,8 +308,12 @@ int DoCtrlDeviceMounting(const char *rootfs) int DoDirectoryMounting(const char *rootfs, const struct MountList *list) { - int ret; + if (rootfs == NULL || list == NULL) { + fprintf(stderr, "rootfs, list pointer is null!\n"); + return -1; + } + int ret; for (unsigned int i = 0; i < list->count; i++) { ret = MountDir(rootfs, (const char *)&list->list[i][0]); if (ret < 0) { @@ -292,8 +329,12 @@ int DoDirectoryMounting(const char *rootfs, const struct MountList *list) int DoFileMounting(const char *rootfs, const struct MountList *list) { - int ret; + if (rootfs == NULL || list == NULL) { + fprintf(stderr, "rootfs, list pointer is null!\n"); + return -1; + } + int ret; for (unsigned int i = 0; i < list->count; i++) { ret = MountFile(rootfs, (const char *)&list->list[i][0]); if (ret < 0) { @@ -309,6 +350,11 @@ int DoFileMounting(const char *rootfs, const struct MountList *list) int DoMounting(const struct ParsedConfig *config) { + if (config == NULL) { + fprintf(stderr, "config pointer is null!\n"); + return -1; + } + int ret; ret = DoDeviceMounting(config->rootfs, (IsVirtual() ? VDEVICE_NAME : DEVICE_NAME), diff --git a/cli/src/utils.c b/cli/src/utils.c index db7b6e4..b35cb23 100644 --- a/cli/src/utils.c +++ b/cli/src/utils.c @@ -18,6 +18,11 @@ char *FormatLogMessage(char *format, ...) { + if (format == NULL) { + fprintf(stderr, "format pointer is null!\n"); + return NULL; + } + va_list list; // 获取格式化后字符串的长度 va_start(list, format); @@ -55,6 +60,11 @@ int StrHasPrefix(const char *str, const char *prefix) int MkDir(const char *dir, int mode) { + if (dir == NULL) { + fprintf(stderr, "dir pointer is null!\n"); + return -1; + } + return mkdir(dir, mode); } @@ -68,6 +78,11 @@ int VerifyPathInfo(const struct PathInfo* pathInfo) int CheckDirExists(const char *dir) { + if (dir == NULL) { + fprintf(stderr, "dir pointer is null!\n"); + return -1; + } + DIR *ptr = opendir(dir); if (NULL == ptr) { return -1; @@ -79,6 +94,11 @@ int CheckDirExists(const char *dir) int GetParentPathStr(const char *path, char *parent, size_t bufSize) { + if (path == NULL || parent == NULL) { + fprintf(stderr, "path pointer or parentPath is null!\n"); + return -1; + } + char *ptr = strrchr(path, '/'); if (ptr == NULL) { return 0; @@ -99,6 +119,11 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize) int MakeDirWithParent(const char *path, mode_t mode) { + if (path == NULL) { + fprintf(stderr, "path pointer is null!\n"); + return -1; + } + if (*path == '\0' || *path == '.') { return 0; } @@ -122,6 +147,11 @@ int MakeDirWithParent(const char *path, mode_t mode) int MakeMountPoints(const char *path, mode_t mode) { + if (path == NULL) { + fprintf(stderr, "path pointer is null!\n"); + return -1; + } + /* directory */ char parentDir[BUF_SIZE] = {0}; GetParentPathStr(path, parentDir, BUF_SIZE); @@ -155,6 +185,11 @@ int MakeMountPoints(const char *path, mode_t mode) int CheckLegality(const char* filename) { + if (filename == NULL) { + fprintf(stderr, "filename pointer is null!\n"); + return -1; + } + char buf[PATH_MAX + 1] = {0x00}; errno_t ret = strncpy_s(buf, PATH_MAX + 1, filename, strlen(filename)); if (ret != EOK) { diff --git a/install/deb/src/main.c b/install/deb/src/main.c index d3c8ee6..0210e91 100644 --- a/install/deb/src/main.c +++ b/install/deb/src/main.c @@ -28,8 +28,9 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize) { if (pf == NULL || text == NULL) { fprintf(stderr, "file pointer or text pointer are null!\n"); - return NULL; + return; } + (void)fseek(pf, 0, SEEK_END); int size = (int)ftell(pf); @@ -47,10 +48,11 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize) static cJSON *CreateAscendRuntimeInfo(const char *runtimePath) { - if (runtimePath = NULL) { + if (runtimePath == NULL) { fprintf(stderr, "runtimePath pointer are null!\n"); return NULL; } + cJSON *root = NULL; root = cJSON_CreateObject(); if (root == NULL) { @@ -87,6 +89,7 @@ static cJSON *CreateRuntimes(const char *runtimePath) fprintf(stderr, "runtimePath pointer is null!\n"); return NULL; } + cJSON *ascendRuntime = NULL; ascendRuntime = CreateAscendRuntimeInfo(runtimePath); if (ascendRuntime == NULL) { @@ -111,8 +114,9 @@ static int DelJsonContent(cJSON *root, const char *key) { if (root == NULL || key == NULL) { fprintf(stderr, "userInfo pointer is null!\n"); - return NULL; + return -1; } + cJSON *existItem = NULL; existItem = cJSON_GetObjectItem(root, key); if (existItem == NULL) { @@ -136,6 +140,7 @@ static cJSON *CreateContent(const char *runtimePath) fprintf(stderr, "runtimePath pointer is null!\n"); return NULL; } + /* 插入ascend runtime */ cJSON *runtimes = NULL; runtimes = CreateRuntimes(runtimePath); @@ -174,6 +179,7 @@ static cJSON *ModifyContent(FILE *pf, const char *runtimePath) fprintf(stderr, "file pointer or runtimePath pointer is null!\n"); return NULL; } + char jsonStr[MAX_JSON_FILE_SIZE] = {0x0}; ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE); @@ -231,6 +237,7 @@ static cJSON *RemoveContent(FILE *pf) fprintf(stderr, "file pointer is null!\n"); return NULL; } + char jsonStr[MAX_JSON_FILE_SIZE] = {0x0}; ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE); @@ -269,10 +276,11 @@ static cJSON *RemoveContent(FILE *pf) static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, const char *runtimePath) { - if (filePath = NULL || tempPath = NULL || runtimePath = NULL) { - fprintf(stderr, "filePath Pointer or tempPath or runtimePath are null!\n"); + if (filePath == NULL || tempPath == NULL || runtimePath == NULL) { + fprintf(stderr, "filePath, tempPath or runtimePath are null!\n"); return -1; } + cJSON *root = NULL; FILE *pf = NULL; pf = fopen(filePath, "r+"); @@ -310,9 +318,10 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c static int CreateRevisedJsonFile(const char *filePath, const char *tempPath) { if (filePath == NULL || tempPath == NULL) { - fprintf(stderr, "filePath Pointer or tempPath are null!\n"); + fprintf(stderr, "filePath or tempPath are null!\n"); return -1; } + FILE *pf = NULL; pf = fopen(filePath, "r+"); if (pf == NULL) {