summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Huang <shawn.p.huang@gmail.com>2009-10-01 09:17:34 +0800
committerPeng Huang <shawn.p.huang@gmail.com>2009-10-01 09:17:34 +0800
commiteaaf6a123092e316bebcf2a1d597fd216921c10a (patch)
treedf6f615930dfedb57e239af94de6f498c0850f1e /src
parent2ef56713a13c750257203182cea398f1309b8ede (diff)
downloadibus-libpinyin-eaaf6a123092e316bebcf2a1d597fd216921c10a.tar.gz
ibus-libpinyin-eaaf6a123092e316bebcf2a1d597fd216921c10a.tar.xz
ibus-libpinyin-eaaf6a123092e316bebcf2a1d597fd216921c10a.zip
Use g_strlcpy and g_strlcat to avoid buffer overflow
Diffstat (limited to 'src')
-rw-r--r--src/Database.cc4
-rw-r--r--src/Phrase.h2
-rw-r--r--src/PinyinParser.cc6
3 files changed, 7 insertions, 5 deletions
diff --git a/src/Database.cc b/src/Database.cc
index 0015b1a..0f46920 100644
--- a/src/Database.cc
+++ b/src/Database.cc
@@ -403,7 +403,9 @@ Database::query (const PinyinArray &pinyin,
result.setSize (result.length () + 1);
Phrase &p = result[result.length() - 1];
- strcpy (p.phrase, (gchar *) sqlite3_column_text (stmt, DB_COLUMN_PHRASE));
+ g_strlcpy (p.phrase,
+ (gchar *) sqlite3_column_text (stmt, DB_COLUMN_PHRASE),
+ sizeof (p.phrase));
p.freq = sqlite3_column_int (stmt, DB_COLUMN_FREQ);
p.user_freq = sqlite3_column_int (stmt, DB_COLUMN_USER_FREQ);
p.len = pinyin_len;
diff --git a/src/Phrase.h b/src/Phrase.h
index 66f674d..2fa26ea 100644
--- a/src/Phrase.h
+++ b/src/Phrase.h
@@ -29,7 +29,7 @@ struct _Phrase {
Phrase & operator += (const Phrase & a) {
g_assert (len + a.len <= MAX_PHRASE_LEN);
- strcat (phrase, a.phrase);
+ g_strlcat (phrase, a.phrase, sizeof (phrase));
for (guint i = 0; i < a.len; i++) {
pinyin_id[len + i][0] = a.pinyin_id[i][0];
pinyin_id[len + i][1] = a.pinyin_id[i][1];
diff --git a/src/PinyinParser.cc b/src/PinyinParser.cc
index 34561fd..d17d8a7 100644
--- a/src/PinyinParser.cc
+++ b/src/PinyinParser.cc
@@ -23,7 +23,7 @@ is_pinyin (const gchar *p,
gint len,
guint option)
{
- gchar buf[7];
+ gchar buf[8];
const Pinyin *result;
if (G_UNLIKELY (len > 6))
@@ -224,8 +224,8 @@ PinyinParser::isPinyin (gint sheng, gint yun, guint option)
const Pinyin *result;
gchar buf[8];
- strcpy (buf, id_map[sheng]);
- strcat (buf, id_map[yun]);
+ g_strlcpy (buf, id_map[sheng], sizeof (buf));
+ g_strlcat (buf, id_map[yun], sizeof (buf));
result = (const Pinyin *) bsearch (buf, pinyin_table, PINYIN_TABLE_NR,
sizeof (Pinyin), py_cmp);