summaryrefslogtreecommitdiff
path: root/src/bin/eolian/common_funcs.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-07-30 13:59:16 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-07-30 13:59:16 +0100
commitec48df78c3e13e70dd9685db468573c7e64639c1 (patch)
treeacd2c4349ad81e18252ac2b4d215c9e8b9d89f26 /src/bin/eolian/common_funcs.c
parent1c5bd5e502824cfb5efec89c0abba353c032c4c7 (diff)
eolian/generator: actually overrun-safe buffer fill
Diffstat (limited to '')
-rw-r--r--src/bin/eolian/common_funcs.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/bin/eolian/common_funcs.c b/src/bin/eolian/common_funcs.c
index bbe24c1410..d00effd2f0 100644
--- a/src/bin/eolian/common_funcs.c
+++ b/src/bin/eolian/common_funcs.c
@@ -24,6 +24,13 @@ _class_name_concatenate(const Eolian_Class *class, char *buffer)
24 eina_iterator_free(itr); 24 eina_iterator_free(itr);
25} 25}
26 26
27static char *
28_fill_envs(char *dest, const char *src, size_t bufs) {
29 strncpy(dest, src, bufs - 1);
30 dest[bufs - 1] = '\0';
31 return dest;
32}
33
27void 34void
28_class_env_create(const Eolian_Class *class, const char *over_classname, _eolian_class_vars *env) 35_class_env_create(const Eolian_Class *class, const char *over_classname, _eolian_class_vars *env)
29{ 36{
@@ -33,22 +40,22 @@ _class_env_create(const Eolian_Class *class, const char *over_classname, _eolian
33 char *p; 40 char *p;
34 41
35 if (!class) 42 if (!class)
36 strncpy(env->full_classname, over_classname, PATH_MAX - 1); 43 _fill_envs(env->full_classname, over_classname, sizeof(env->full_classname));
37 else 44 else
38 _class_name_concatenate(class, env->full_classname); 45 _class_name_concatenate(class, env->full_classname);
39 46
40 /* class/CLASS*/ 47 /* class/CLASS*/
41 p = strncpy(env->upper_classname, env->full_classname, PATH_MAX - 1); 48 p = _fill_envs(env->upper_classname, env->full_classname, sizeof(env->upper_classname));
42 eina_str_toupper(&p); 49 eina_str_toupper(&p);
43 p = strncpy(env->lower_classname, env->full_classname, PATH_MAX - 1); 50 p = _fill_envs(env->lower_classname, env->full_classname, sizeof(env->lower_classname));
44 eina_str_tolower(&p); 51 eina_str_tolower(&p);
45 52
46 /* eo_prefix */ 53 /* eo_prefix */
47 if (class) eo_prefix = eolian_class_eo_prefix_get(class); 54 if (class) eo_prefix = eolian_class_eo_prefix_get(class);
48 if (!eo_prefix) eo_prefix = env->full_classname; 55 if (!eo_prefix) eo_prefix = env->full_classname;
49 p = strncpy(env->upper_eo_prefix, eo_prefix, PATH_MAX - 1); 56 p = _fill_envs(env->upper_eo_prefix, eo_prefix, sizeof(env->upper_eo_prefix));
50 eina_str_toupper(&p); 57 eina_str_toupper(&p);
51 p = strncpy(env->lower_eo_prefix, eo_prefix, PATH_MAX - 1); 58 p = _fill_envs(env->lower_eo_prefix, eo_prefix, sizeof(env->lower_eo_prefix));
52 eina_str_tolower(&p); 59 eina_str_tolower(&p);
53 60
54 /* classtype */ 61 /* classtype */
@@ -78,23 +85,23 @@ _class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_F
78 char *p; 85 char *p;
79 const Eolian_Function *funcid = eolian_class_function_get_by_name(class, funcname, ftype); 86 const Eolian_Function *funcid = eolian_class_function_get_by_name(class, funcname, ftype);
80 87
81 p = strncpy(env->upper_func, funcname, PATH_MAX - 1); 88 p = _fill_envs(env->upper_func, funcname, sizeof(env->upper_func));
82 eina_str_toupper(&p); 89 eina_str_toupper(&p);
83 90
84 Eolian_Function_Type aftype = ftype; 91 Eolian_Function_Type aftype = ftype;
85 if (aftype == EOLIAN_PROPERTY) aftype = EOLIAN_METHOD; 92 if (aftype == EOLIAN_PROPERTY) aftype = EOLIAN_METHOD;
86 93
87 Eina_Stringshare *fname = eolian_function_full_c_name_get(funcid, aftype, EINA_FALSE); 94 Eina_Stringshare *fname = eolian_function_full_c_name_get(funcid, aftype, EINA_FALSE);
88 strncpy(p = env->upper_eo_func, fname, PATH_MAX - 1); 95 p = _fill_envs(env->upper_eo_func, fname, sizeof(env->upper_eo_func));
89 eina_str_toupper(&p); 96 eina_str_toupper(&p);
90 strncpy(p = env->lower_eo_func, fname, PATH_MAX - 1); 97 p = _fill_envs(env->lower_eo_func, fname, sizeof(env->lower_eo_func));
91 eina_str_tolower(&p); 98 eina_str_tolower(&p);
92 eina_stringshare_del(fname); 99 eina_stringshare_del(fname);
93 100
94 Eina_Stringshare *lname = eolian_function_full_c_name_get(funcid, aftype, EINA_TRUE); 101 Eina_Stringshare *lname = eolian_function_full_c_name_get(funcid, aftype, EINA_TRUE);
95 env->legacy_func[0] = '\0'; 102 env->legacy_func[0] = '\0';
96 if (!lname) return; 103 if (!lname) return;
97 strncpy(p = env->legacy_func, lname, PATH_MAX - 1); 104 p = _fill_envs(env->legacy_func, lname, sizeof(env->legacy_func));
98 eina_stringshare_del(lname); 105 eina_stringshare_del(lname);
99} 106}
100 107