summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 00:46:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 00:46:10 +0000
commit4c009414119347e87d9bb2402617a4585dd3f341 (patch)
tree0ecbaebef0a7a27f5687d1cfed75d6dc5abec351
parent042e5013a3bc42a3637aa1646e9fc002436b852f (diff)
etc.c: encodings
* ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to string members. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/etc/etc.c30
2 files changed, 27 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d20687..f9a3a55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Aug 3 09:46:07 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to
+ string members.
+
Sat Aug 3 09:30:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* struct.c (rb_struct_define_under): new function to define Struct
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 3f14669..18d425a 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -79,6 +79,20 @@ safe_setup_str(const char *str)
if (str == 0) str = "";
return rb_tainted_str_new2(str);
}
+
+static VALUE
+safe_setup_locale_str(const char *str)
+{
+ if (str == 0) str = "";
+ return rb_locale_str_new_cstr(str);
+}
+
+static VALUE
+safe_setup_filesystem_str(const char *str)
+{
+ if (str == 0) str = "";
+ return rb_filesystem_str_new_cstr(str);
+}
#endif
#ifdef HAVE_GETPWENT
@@ -87,17 +101,17 @@ setup_passwd(struct passwd *pwd)
{
if (pwd == 0) rb_sys_fail("/etc/passwd");
return rb_struct_new(sPasswd,
- safe_setup_str(pwd->pw_name),
+ safe_setup_locale_str(pwd->pw_name),
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
safe_setup_str(pwd->pw_passwd),
#endif
UIDT2NUM(pwd->pw_uid),
GIDT2NUM(pwd->pw_gid),
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
- safe_setup_str(pwd->pw_gecos),
+ safe_setup_locale_str(pwd->pw_gecos),
#endif
- safe_setup_str(pwd->pw_dir),
- safe_setup_str(pwd->pw_shell),
+ safe_setup_filesystem_str(pwd->pw_dir),
+ safe_setup_filesystem_str(pwd->pw_shell),
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
INT2NUM(pwd->pw_change),
#endif
@@ -108,10 +122,10 @@ setup_passwd(struct passwd *pwd)
PW_AGE2VAL(pwd->pw_age),
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
- safe_setup_str(pwd->pw_class),
+ safe_setup_locale_str(pwd->pw_class),
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
- safe_setup_str(pwd->pw_comment),
+ safe_setup_locale_str(pwd->pw_comment),
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
INT2NUM(pwd->pw_expire),
@@ -351,11 +365,11 @@ setup_group(struct group *grp)
mem = rb_ary_new();
tbl = grp->gr_mem;
while (*tbl) {
- rb_ary_push(mem, safe_setup_str(*tbl));
+ rb_ary_push(mem, safe_setup_locale_str(*tbl));
tbl++;
}
return rb_struct_new(sGroup,
- safe_setup_str(grp->gr_name),
+ safe_setup_locale_str(grp->gr_name),
#ifdef HAVE_STRUCT_GROUP_GR_PASSWD
safe_setup_str(grp->gr_passwd),
#endif