]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Avoid a buffer overflow if the language file contains more lines than expected.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 13 Jul 2009 08:25:29 +0000 (08:25 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 13 Jul 2009 08:25:29 +0000 (08:25 +0000)
Display the name of the language file being red when displaying the texts.

language.c

index 625747b9cc347fd7026d5604a561bbad4b8796ca..2afa6d3cd283fd101a1f63f2d2eb0f6526d10a6b 100644 (file)
@@ -30,6 +30,7 @@ void language_load(const char *language)
 {
    char lfile[FILENAME_MAX];
    FILE *fp_text;
+   char buf[MAXLEN];
    int record=0;
 
    if (snprintf(lfile,sizeof(lfile),"%s/languages/%s",SYSCONFDIR,language)>=sizeof(lfile)) {
@@ -41,8 +42,10 @@ void language_load(const char *language)
      fprintf(stderr, "SARG: (language) Cannot open language file: %s\n",lfile);
      exit(1);
    }
+   if(langcode)
+      printf("Reading language from %s\n",lfile);
 
-   while(fgets(buf,MAXLEN,fp_text)!=NULL) {
+   while(record<sizeof(text)/sizeof(text[0]) && fgets(buf,sizeof(buf),fp_text)!=NULL) {
       if (getword(warea,sizeof(warea),buf,'"')<0 || getword(warea,sizeof(warea),buf,'"')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",lfile);
          exit(1);