--- gtk/compose.c 2006-12-22 05:32:35.000000000 +0100 +++ gtk/compose.c 2007-06-28 20:00:20.000000000 +0200 @@ -659,22 +664,21 @@ static void ParseComposeStringFile(FILE *fp) { - char tb[8192]; char* tbp; struct stat st; - if (fstat(fileno(fp), &st) != -1) { - unsigned long size = (unsigned long)st.st_size; - if (size <= sizeof tb) - tbp = tb; - else - tbp = (char *)malloc(size); - + if ( + fstat(fileno(fp), &st) != -1 && + S_ISREG(st.st_mode) && + st.st_size > 0 && + st.st_size + (size_t)0 < (off_t)0 + (size_t)-1 + ) { + tbp = (char *)malloc(st.st_size); if (tbp != NULL) { + /* FIXME: If the file grows now, we'll get a buffer overflow. */ while (parse_compose_line(fp, tbp) >= 0) { } - if (tbp != tb) - free (tbp); + free (tbp); } } }