free(line);
// clean file
- fseek(f, 0L, SEEK_SET);
- ftruncate(fileno(f), 0);
+ if (fseek(f, 0L, SEEK_SET) == -1) {
+ int err = errno;
+ LOGE("Failed to set file offset, errno=%d\n", err);
+ return -err;
+ }
+ if (ftruncate(fileno(f), 0) == -1) {
+ int err = errno;
+ LOGE("Failed to truncate file, errno=%d\n", err);
+ return -err;
+ }
// write new names list without 'name'
bool delFlag = false;
{
const char ui_viewer_log[] = "/run/swap/uilib.log";
- if (access(ui_viewer_log, F_OK) != -1)
- remove(ui_viewer_log);
+ if (access(ui_viewer_log, F_OK) != -1) {
+ if (remove(ui_viewer_log) == -1)
+ LOGE("Cannot remove UIHV log file: %s, errno=%d\n",
+ ui_viewer_log, errno);
+ }
if (!auxd_client_tizen_app_start(manager.auxd_client, app_info->app_id)) {
LOGE("Cannot exec tizen app %s\n", app_info->app_id);
#include <glob.h>
#include <stdio.h>
#include <stdlib.h>
+#include <limits.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
return 0;
}
- lseek(pfd, 0, SEEK_SET); // rewind to start of file
+ // rewind to start of file
+ if (lseek(pfd, 0, SEEK_SET) == (off_t)-1)
+ return -errno;
// read from file
if (unlikely(read(pfd, buf, STATUS_STRING_MAX) == -1))
static bool save_to_tmpfile(char *path, int suffixlen,
const char *data, size_t len)
{
+ mode_t old_umask = umask(077);
int fd = mkstemps(path, suffixlen);
+ umask(old_umask);
if (fd == -1) {
LOGE("Cannot make temp file, errno=%d\n", errno);
return false;
continue;
}
- if ((procnode = find_node(*prochead, pidarray[i])) == NULL) {
+ procnode = find_node(*prochead, pidarray[i]);
+ if (procnode == NULL) {
// new process
+ is_new_node = 1;
procnode = add_node(prochead, pidarray[i]);
if (procnode == NULL) {
LOGE("Failed to add node\n");
ret = 1;
- continue;
+ goto exit;
}
- is_new_node = 1;
- }
-
- if (procnode == NULL) {
- LOGE("failed to create new procnode\n");
- ret = errno;
- goto exit;
}
if (datatype == PROCDATA_STAT) {
if (meminfo_fd == -1)
return -1;
- lseek(meminfo_fd, 0L, SEEK_SET);
+ if (lseek(meminfo_fd, 0L, SEEK_SET) == (off_t)-1) {
+ LOGE("Failed to set file offset, errno=%d\n", errno);
+ return -1;
+ }
+
if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
{
LOGE("Failed to read from " PROCMEMINFO "\n");
if (meminfo_fd == -1)
return 0;
- lseek(meminfo_fd, 0L, SEEK_SET);
+ if (lseek(meminfo_fd, 0L, SEEK_SET) == (off_t)-1) {
+ LOGE("Failed to set file offset, errno=%d\n", errno);
+ return 0;
+ }
if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
{
{
head = tail + 1;
totalmem = strtoul(head, &tail, 10);
+ if (totalmem == ULONG_MAX) {
+ LOGE("Failed to read field: %s\n", memtotalstr);
+ return 0;
+ }
break;
}
head = tail + 1;
}
+ if (totalmem >= ULONG_MAX / 1024) {
+ LOGE("Field '%s' is very big\n", memtotalstr);
+ return 0;
+ }
+
return (totalmem * 1024);
}