char *value = NULL;
char *tmp_value;
int value_size = 0;
+ int tmp_value_size = 0;
retry_open:
errno = 0;
case PREFERENCE_TYPE_STRING:
while (fgets(file_buf, sizeof(file_buf), fp)) {
if (value) {
- value_size = value_size + strlen(file_buf);
- tmp_value = (char *) realloc(value, value_size);
+ tmp_value_size = value_size + sizeof(file_buf);
+ tmp_value = (char *) realloc(value, tmp_value_size);
if (tmp_value == NULL) {
func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
free(value);
value = NULL;
break;
}
+
+ memset(tmp_value + value_size , 0x00, sizeof(file_buf));
+ strncat(tmp_value, file_buf, tmp_value_size - strlen(tmp_value));
value = tmp_value;
- strncat(value, file_buf, strlen(file_buf));
+
+ value_size = tmp_value_size;
+ memset(file_buf, 0x00, sizeof(file_buf));
} else {
- value_size = strlen(file_buf) + 1;
+ value_size = sizeof(file_buf) + 1;
value = (char *)malloc(value_size);
if (value == NULL) {
func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
break;
}
memset(value, 0x00, value_size);
- strncpy(value, file_buf, strlen(file_buf));
+ strncpy(value, file_buf, value_size - 1);
}
}
return entry.gr_gid;
}
-static int _make_key_path(const char *pkgid, const char *keyname, char *path)
+static int _make_key_path(const char *pkgid, const char *keyname, char **path)
{
const char *key;
gchar *convert_key;
char pref_dir[PATH_MAX];
- char cmd[PATH_MAX];
+ char *cmd;
+ int size;
mode_t dir_mode = 0664 | 0111;
const char *pkg_path;
uid_t uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
}
}
- snprintf(cmd, sizeof(cmd),
+ size = snprintf(0, 0, "/usr/bin/chsmack -t -a User::Pkg::\"%s\" %s",
+ pkgid, pref_dir);
+ cmd = (char *)malloc(size + 1);
+ if (cmd == NULL) {
+ printf("Out of memory\n");
+ return -1;
+ }
+
+ snprintf(cmd, size,
"/usr/bin/chsmack -t -a User::Pkg::\"%s\" %s",
pkgid, pref_dir);
if (__system(cmd)) {
printf("[pref] cmd error()\n");
+ free(cmd);
return -1;
}
+ free(cmd);
convert_key = g_compute_checksum_for_string(G_CHECKSUM_SHA1,
keyname, strlen(keyname));
}
key = (const char *)convert_key;
- snprintf(path, PATH_MAX, "%s/%s", pref_dir, key);
+
+ size = snprintf(0, 0, "%s/%s", pref_dir, key);
+ *path = (char *)malloc(size + 1);
+ if (*path == NULL) {
+ printf("Out of memory\n");
+ g_free(convert_key);
+ return -1;
+ }
+
+ snprintf(*path, size, "%s/%s", pref_dir, key);
g_free(convert_key);
return 0;
{
FILE *fp;
int ret;
- char key_path[PATH_MAX] = {0,};
+ char *key_path;
size_t keyname_len;
int type_i;
int temp_i;
double temp_d;
locale_t loc;
- _make_key_path(pkgid, key, key_path);
+ _make_key_path(pkgid, key, &key_path);
retry:
fp = fopen(key_path, "r+");
if (fp == NULL) {
if (_create_key(key_path, pkgid) == -1) {
printf("preference key failed to create.(%d/%s)\n",
errno, strerror(errno));
+ free(key_path);
return -1;
}
if (ret <= 0) {
printf("preference write key name length error(%d/%s)\n",
errno, strerror(errno));
+ free(key_path);
fclose(fp);
return -1;
}
if (ret <= 0) {
printf("preference write key name length error(%d/%s)\n",
errno, strerror(errno));
+ free(key_path);
fclose(fp);
return -1;
}
type_i = PREFERENCE_TYPE_STRING;
} else {
printf("key type is invalid.int|double|bool|string\n");
+ free(key_path);
fclose(fp);
return -1;
}
break;
}
+ free(key_path);
+
uselocale(LC_GLOBAL_LOCALE);
fflush(fp);
if (fp) {
char file_buf[BUF_LEN] = {0,};
char *value_str = NULL;
size_t value_size = 0;
+ size_t new_value_size = 0;
size_t diff;
size_t file_buf_size;
char *new_value_str;
case PREFERENCE_TYPE_STRING:
while (fgets(file_buf, sizeof(file_buf), fp)) {
if (value_str) {
- file_buf_size = strlen(file_buf);
+ file_buf_size = sizeof(file_buf);
diff = INT_MAX - file_buf_size;
if (value_size > diff) {
printf("Integer overflow\n");
break;
}
- value_size += file_buf_size;
+ new_value_size = value_size + file_buf_size;
new_value_str = (char *)realloc(value_str,
- value_size);
+ new_value_size);
if (new_value_str == NULL)
break;
+ memset(new_value_str + value_size, 0x00, sizeof(file_buf));
+ strncat(new_value_str, file_buf, new_value_size - strlen(new_value_str));
+
value_str = new_value_str;
- strncat(value_str, file_buf, strlen(file_buf));
+ value_size = new_value_size;
+ memset(file_buf, 0x00, sizeof(file_buf));
} else {
- value_size = strlen(file_buf) + 1;
+ value_size = sizeof(file_buf) + 1;
value_str = (char *)malloc(value_size);
if (value_str == NULL)
break;
memset(value_str, 0x00, value_size);
- strncpy(value_str, file_buf, strlen(file_buf));
+ strncpy(value_str, file_buf, value_size - 1);
}
}
static void _print_preference_key(const char *pkgid, const char *key)
{
- char key_path[PATH_MAX] = {0,};
+ char *key_path;
- _make_key_path(pkgid, key, key_path);
+ _make_key_path(pkgid, key, &key_path);
_print_pref_value_from_file_path(key_path, key);
+
+ free(key_path);
}
static void _print_preference_in_package(const char *pkgid)
{
char pref_dir[PATH_MAX];
DIR *dir;
- int dfd;
+ int dfd, res, size;
struct stat st;
- int res;
struct dirent *ent = NULL;
const char *name;
char *keyname = NULL;
- char file_full_path[PATH_MAX];
+ char *file_full_path;
const char *pkg_path;
pkg_path = __get_package_path(pkgid);
continue;
}
- snprintf(file_full_path, sizeof(file_full_path), "%s/%s",
- pref_dir, name);
+ size = snprintf(0, 0, "%s/%s", pref_dir, name);
+ file_full_path = (char *)malloc(size + 1);
+ if (file_full_path == NULL) {
+ printf("Out of memory\n");
+ closedir(dir);
+ return;
+ }
+
+ snprintf(file_full_path, size, "%s/%s", pref_dir, name);
_get_key_name(file_full_path, &keyname);
_print_pref_value_from_file_path(file_full_path, keyname);
+ free(file_full_path);
if (keyname) {
free(keyname);
keyname = NULL;
{
DIR *dir;
struct dirent *ent;
- char old_file[BUF_LEN];
- char new_file[BUF_LEN];
+ char *old_file;
+ char *new_file;
gchar *convert_key;
char _key[PREFERENCE_KEY_PATH_LEN] = {0,};
char *chrptr = NULL;
+ int size;
dir = opendir(pref_dir);
if (!dir)
if (ent->d_type != DT_REG)
continue;
- snprintf(old_file, sizeof(old_file), "%s/%s", pref_dir,
- ent->d_name);
+ size = snprintf(0, 0, "%s/%s", pref_dir, ent->d_name);
+ old_file = (char *)malloc(size + 1);
+ if (old_file == NULL) {
+ printf("Out of memory\n");
+ closedir(dir);
+ return -1;
+ }
+
+ snprintf(old_file, size, "%s/%s", pref_dir, ent->d_name);
strncpy(_key, ent->d_name, PREFERENCE_KEY_PATH_LEN - 1);
_key, strlen(_key));
if (convert_key == NULL) {
printf("fail to convert key\n");
+ free(old_file);
closedir(dir);
return -1;
}
- snprintf(new_file, sizeof(new_file), "%s/%s", pref_dir,
- convert_key);
+
+ size = snprintf(0, 0, "%s/%s", pref_dir, convert_key);
+ new_file = (char *)malloc(size + 1);
+ if (new_file == NULL) {
+ printf("Out of memory\n");
+ free(old_file);
+ g_free(convert_key);
+ closedir(dir);
+ return -1;
+ }
+
+ snprintf(new_file, size, "%s/%s", pref_dir, convert_key);
+
g_free(convert_key);
if (rename(old_file, new_file) < 0) {
if (_add_key_info_to_file(new_file, _key) < 0)
printf("convert %s file failed\n", new_file);
+
+ free(old_file);
+ free(new_file);
}
closedir(dir);
strcmp(ent->d_name, "..") == 0)
continue;
- snprintf(buf, sizeof(buf), "%s/%s/data/.pref",
+ snprintf(buf, sizeof(buf) - 1, "%s/%s/data/.pref",
app_dir, ent->d_name);
if (access(buf, F_OK) == -1)
continue;