From: Bruno Haible Date: Fri, 19 Sep 2003 08:32:51 +0000 (+0000) Subject: More reliable checking for read errors. X-Git-Tag: v0.13~241 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e639c90ee1c61d128b612ebfbd067f496c64c285;p=thirdparty%2Fgettext.git More reliable checking for read errors. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 8fa8b8472..77d2859c1 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,12 @@ +2003-09-14 Bruno Haible + + More reliable checking for read errors. + * po-lex.c (mbfile_getc): Diagnose read errors also in the middle of + multibyte characters. + (lex_getc): Diagnose read errors also right after backslash. + * x-rst.c (extract_rst): Diagnose read errors also inside ConstName + and immediately after #. + 2003-09-14 Bruno Haible * write-mo.c: Include fwriterror.h. @@ -1182,4 +1191,4 @@ * user-email.in: Use 'gettext' instead of @PACKAGE@. -See ChangeLog.0 for earlier changes. +See ChangeLog.0 for earlier changes. \ No newline at end of file diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index 9564e2b29..afc8ac6cd 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -389,6 +389,8 @@ mbfile_init (mbfile_t mbf, FILE *stream) mbf->bufcount = 0; } +/* Read the next multibyte character from mbf and put it into mbc. + If a read error occurs, errno is set and ferror (mbf->fp) becomes true. */ static void mbfile_getc (mbchar_t mbc, mbfile_t mbf) { @@ -478,6 +480,8 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) if (c == EOF) { mbf->eof_seen = true; + if (ferror (mbf->fp)) + goto eof; if (signal_eilseq) po_gram_error (_("\ incomplete multibyte sequence at end of file")); @@ -535,7 +539,15 @@ incomplete multibyte sequence at end of line")); { /* Read one more byte. */ int c = getc (mbf->fp); - if (c != EOF) + if (c == EOF) + { + if (ferror (mbf->fp)) + { + mbf->eof_seen = true; + goto eof; + } + } + else { mbf->buf[1] = (unsigned char) c; mbf->bufcount++; @@ -649,8 +661,11 @@ lex_getc (mbchar_t mbc) if (mb_iseof (mbc)) { if (ferror (mbf->fp)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - gram_pos.file_name); + { + bomb: + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + gram_pos.file_name); + } break; } @@ -669,10 +684,16 @@ lex_getc (mbchar_t mbc) mbfile_getc (mbc2, mbf); + if (mb_iseof (mbc2)) + { + if (ferror (mbf->fp)) + goto bomb; + break; + } + if (!mb_iseq (mbc2, '\n')) { - if (!mb_iseof (mbc2)) - mbfile_ungetc (mbc2, mbf); + mbfile_ungetc (mbc2, mbf); break; } diff --git a/gettext-tools/src/x-rst.c b/gettext-tools/src/x-rst.c index 15aa4fbcb..15bf6b501 100644 --- a/gettext-tools/src/x-rst.c +++ b/gettext-tools/src/x-rst.c @@ -116,6 +116,8 @@ extract_rst (FILE *f, break; buffer[bufpos++] = c; c = getc (f); + if (c == EOF && ferror (f)) + goto bomb; } buffer[bufpos] = '\0'; location = xstrdup (buffer); @@ -160,6 +162,8 @@ extract_rst (FILE *f, { int n; c = getc (f); + if (c == EOF && ferror (f)) + goto bomb; if (c == EOF || !isdigit (c)) { error_with_progname = false; @@ -222,6 +226,9 @@ extract_rst (FILE *f, } if (ferror (f)) - error (EXIT_FAILURE, errno, _("error while reading \"%s\""), - real_filename); + { + bomb: + error (EXIT_FAILURE, errno, _("error while reading \"%s\""), + real_filename); + } }