Author: iratqq
Date: Mon Apr 7 12:33:35 2008
New Revision: 5397
Modified:
trunk/fep/udsock.c
trunk/uim/m17nlib.c
trunk/uim/plugin.c
trunk/uim/skk.c
trunk/uim/uim-notify.c
Log:
* uim/plugin.c (plugin_load):
- Fix misused snprintf(3).
* uim/uim-notify.c (notify_get_plugins):
- Ditto.
* uim/m17nlib.c
(find_im_by_name):
- Ditto.
(get_input_method_name):
- Ditto. Plug memleak.
* uim/skk.c (open_lock, skk_save_personal_dictionary):
- Ditto.
* fep/udsock.c (usersockname):
- Ditto.
Modified: trunk/fep/udsock.c
==============================================================================
--- trunk/fep/udsock.c (original)
+++ trunk/fep/udsock.c Mon Apr 7 12:33:35 2008
@@ -114,7 +114,7 @@
sendline("uim-fep cannot create directory");
exit(EXIT_FAILURE);
}
- snprintf(buf, UNIX_PATH_MAX, "%s/%s", sock_dir, filebuf);
+ snprintf(buf, sizeof(buf), "%s/%s", sock_dir, filebuf);
return buf;
}
Modified: trunk/uim/m17nlib.c
==============================================================================
--- trunk/uim/m17nlib.c (original)
+++ trunk/uim/m17nlib.c Mon Apr 7 12:33:35 2008
@@ -437,18 +437,15 @@
get_input_method_name(uim_lisp nth_)
{
int len, nth;
- char *name;
+ char name[BUFSIZ];
nth = C_INT(nth_);
if (nth < nr_input_methods) {
- len = strlen(im_array[nth].lang) + strlen(im_array[nth].name) + 7;
- name = alloca(len);
-
if (!strcmp(im_array[nth].lang, "t"))
- snprintf(name, len, "m17n-%s", im_array[nth].name);
+ snprintf(name, sizeof(name), "m17n-%s", im_array[nth].name);
else
- snprintf(name, len, "m17n-%s-%s", im_array[nth].lang,
im_array[nth].name);
+ snprintf(name, sizeof(name), "m17n-%s-%s", im_array[nth].lang,
im_array[nth].name);
return MAKE_STR(name);
}
@@ -566,9 +563,9 @@
char buf[100];
if (!strcmp(im_array[i].lang, "t"))
- snprintf(buf, 100, "%s", im_array[i].name);
+ strlcpy(buf, im_array[i].name, sizeof(buf));
else
- snprintf(buf, 100, "%s-%s", im_array[i].lang, im_array[i].name);
+ snprintf(buf, sizeof(buf), "%s-%s", im_array[i].lang, im_array[i].name);
if (!strcmp(im_name, buf))
return im_instance(i);
Modified: trunk/uim/plugin.c
==============================================================================
--- trunk/uim/plugin.c (original)
+++ trunk/uim/plugin.c Mon Apr 7 12:33:35 2008
@@ -95,7 +95,7 @@
plugin_load(uim_lisp _name)
{
const char *plugin_name;
- char *plugin_lib_filename = NULL, *plugin_scm_filename = NULL;
+ char plugin_lib_filename[MAXPATHLEN], plugin_scm_filename[MAXPATHLEN];
uim_lisp lib_path = uim_scm_eval_c_string("uim-plugin-lib-load-path");
uim_lisp scm_path = uim_scm_eval_c_string("uim-plugin-scm-load-path");
uim_lisp path_car, path_cdr;
@@ -121,9 +121,7 @@
const char *path;
path_car = CAR(path_cdr);
path = REFER_C_STR(path_car);
- len = strlen(path) + 1 + strlen(PLUGIN_PREFIX) +
strlen(plugin_name)+ strlen(PLUGIN_SUFFIX) + 1;
- plugin_lib_filename = uim_malloc(sizeof(char) * len);
- snprintf(plugin_lib_filename, len, "%s/%s%s%s",
+ snprintf(plugin_lib_filename, sizeof(plugin_lib_filename), "%s/%s%s%s",
path, PLUGIN_PREFIX, plugin_name, PLUGIN_SUFFIX);
fd = open(plugin_lib_filename, O_RDONLY);
if (fd >= 0) {
@@ -131,8 +129,7 @@
DPRINTFN(UIM_VLEVEL_PLUGIN, (stderr, "Found %s.\n", plugin_lib_filename));
break;
}
- free(plugin_lib_filename);
- plugin_lib_filename = NULL;
+ plugin_lib_filename[0] = '\0';
}
DPRINTFN(UIM_VLEVEL_PLUGIN, (stderr, "Searching %s.scm.\n", plugin_name));
@@ -144,31 +141,25 @@
const char *path;
path_car = CAR(path_cdr);
path = REFER_C_STR(path_car);
- len = strlen(path) + 1 + strlen(plugin_name)+ strlen(".scm") + 1;
- plugin_scm_filename = uim_malloc(sizeof(char) * len);
- snprintf(plugin_scm_filename, len, "%s/%s.scm", path, plugin_name);
+ snprintf(plugin_scm_filename,
sizeof(plugin_scm_filename), "%s/%s.scm", path, plugin_name);
fd = open(plugin_scm_filename, O_RDONLY);
if (fd >= 0) {
close(fd);
DPRINTFN(UIM_VLEVEL_PLUGIN, (stderr, "Found %s.\n", plugin_scm_filename));
break;
}
- free(plugin_scm_filename);
- plugin_scm_filename = NULL;
+ plugin_scm_filename[0] = '\0';
}
- if (plugin_lib_filename == NULL) {
- free(plugin_scm_filename);
+ if (plugin_lib_filename[0] == '\0') {
return uim_scm_f();
}
DPRINTFN(UIM_VLEVEL_PLUGIN, (stderr, "Loading libuim-%s.so.\n", plugin_name));
library = dlopen(plugin_lib_filename, RTLD_NOW);
- free(plugin_lib_filename);
if (library == NULL) {
uim_notify_fatal(N_("%s plugin: Load failed."), dlerror());
- free(plugin_scm_filename);
return uim_scm_f();
}
@@ -178,7 +169,6 @@
= (void (*)(void))dlfunc(library, "uim_plugin_instance_quit");
if (!plugin_instance_init) {
uim_notify_fatal(N_("%s plugin: Init failed."), plugin_name);
- free(plugin_scm_filename);
return uim_scm_f();
}
@@ -194,7 +184,6 @@
* comment of uim-notify.h -- YamaKen 2008-02-11 */
uim_notify_fatal(N_("%s plugin: Subsequent %s load failed."),
plugin_name, plugin_scm_filename);
- free(plugin_scm_filename);
return uim_scm_f();
}
}
@@ -208,7 +197,6 @@
MAKE_FPTR(plugin_instance_quit));
uim_scm_eval(form);
}
- free(plugin_scm_filename);
return uim_scm_t();
}
Modified: trunk/uim/skk.c
==============================================================================
--- trunk/uim/skk.c (original)
+++ trunk/uim/skk.c Mon Apr 7 12:33:35 2008
@@ -50,6 +50,7 @@
#include <errno.h>
#include <sys/socket.h>
#include <netdb.h>
+#include <pwd.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
@@ -2841,11 +2842,9 @@
{
int fd, len;
struct flock fl;
- char *lock_fn;
+ char lock_fn[MAXPATHLEN];
- len = strlen(name) + strlen(".lock") + 1;
- lock_fn = uim_malloc(len);
- snprintf(lock_fn, len, "%s.lock", name);
+ snprintf(lock_fn, sizeof(lock_fn), "%s.lock", name);
fd = open(lock_fn, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1) {
@@ -2862,7 +2861,6 @@
fd = -1;
}
- free(lock_fn);
return fd;
}
@@ -3187,7 +3185,7 @@
{
FILE *fp;
const char *fn = REFER_C_STR(fn_);
- char *tmp_fn = NULL;
+ char tmp_fn[MAXPATHLEN];
struct skk_line *sl;
struct stat st;
int len, lock_fd = -1;
@@ -3203,10 +3201,8 @@
}
lock_fd = open_lock(fn, F_WRLCK);
- len = strlen(fn) + 5;
- tmp_fn = uim_malloc(len);
- snprintf(tmp_fn, len, "%s.tmp", fn);
+ snprintf(tmp_fn, sizeof(tmp_fn), "%s.tmp", fn);
umask_val = umask(S_IRGRP | S_IROTH | S_IWGRP | S_IWOTH);
fp = fopen(tmp_fn, "w");
umask(umask_val);
@@ -3235,7 +3231,6 @@
error:
close_lock(lock_fd);
- free(tmp_fn);
return uim_scm_f();
}
Modified: trunk/uim/uim-notify.c
==============================================================================
--- trunk/uim/uim-notify.c (original)
+++ trunk/uim/uim-notify.c Mon Apr 7 12:33:35 2008
@@ -250,7 +250,7 @@
(strcmp(dp->d_name + len - slen, NOTIFY_PLUGIN_SUFFIX) != 0))
continue;
- snprintf(path, PATH_MAX, "%s/%s", NOTIFY_PLUGIN_PATH, dp->d_name);
+ snprintf(path, sizeof(path), "%s/%s", NOTIFY_PLUGIN_PATH, dp->d_name);
handle = dlopen(path, RTLD_NOW);
if ((str = dlerror()) != NULL) {
fprintf(stderr, "load failed %s(%s)\n", path, str);