summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-05-19 16:47:08 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-05-19 16:47:08 +0200
commitf3b32f8cb94bc83ded97bec478e666be6a07bf0d (patch)
tree431d0906aa4e3dad4d92566c928c5d32c4635a9d
parentf25d15a4574139ff080a9278d3b248a15be45e43 (diff)
downloadabrt-f3b32f8cb94bc83ded97bec478e666be6a07bf0d.tar.gz
abrt-f3b32f8cb94bc83ded97bec478e666be6a07bf0d.tar.xz
abrt-f3b32f8cb94bc83ded97bec478e666be6a07bf0d.zip
dump_dir: fix loading of Unicode texts. Closes bz#622223
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--src/gui-wizard-gtk/wizard.c6
-rw-r--r--src/lib/dump_dir.c30
2 files changed, 28 insertions, 8 deletions
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 414b501f..bd5d28c4 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -207,10 +207,14 @@ struct dump_dir *steal_if_needed(struct dump_dir *dd)
dd_close(dd);
char *HOME = getenv("HOME");
+ if (!HOME || !HOME[0])
+ {
+ struct passwd *pw = getpwuid(getuid());
+ HOME = pw ? pw->pw_dir : NULL;
+ }
if (HOME && HOME[0])
HOME = concat_path_file(HOME, ".abrt/spool");
else
-//TODO: try to find homedir in password db?
HOME = xstrdup("/tmp");
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g_assistant),
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 0c6467f4..03097ce1 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -651,21 +651,37 @@ static char *load_text_file(const char *path, unsigned flags)
int ch;
while ((ch = fgetc(fp)) != EOF)
{
+//TODO? \r -> \n?
+//TODO? strip trailing spaces/tabs?
if (ch == '\n')
oneline = (oneline << 1) | 1;
if (ch == '\0')
ch = ' ';
- if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
+ if (isspace(ch) || ch >= ' ') /* used !iscntrl, but it failed on unicode */
strbuf_append_char(buf_content, ch);
}
fclose(fp);
- /* If file contains exactly one '\n' and it is at the end, remove it.
- * This enables users to use simple "echo blah >file" in order to create
- * short string items in dump dirs.
- */
- if (oneline == 1 && buf_content->buf[buf_content->len - 1] == '\n')
- buf_content->buf[--buf_content->len] = '\0';
+ char last = oneline != 0 ? buf_content->buf[buf_content->len - 1] : 0;
+ if (last == '\n')
+ {
+ /* If file contains exactly one '\n' and it is at the end, remove it.
+ * This enables users to use simple "echo blah >file" in order to create
+ * short string items in dump dirs.
+ */
+ if (oneline == 1)
+ buf_content->buf[--buf_content->len] = '\0';
+ }
+ else /* last != '\n' */
+ {
+ /* Last line is unterminated, fix it */
+ /* Cases: */
+ /* oneline=0: "qwe" - DONT fix this! */
+ /* oneline=1: "qwe\nrty" - two lines in fact */
+ /* oneline>1: "qwe\nrty\uio" */
+ if (oneline >= 1)
+ strbuf_append_char(buf_content, '\n');
+ }
return strbuf_free_nobuf(buf_content);
}