Commit ae70f5c6 authored by Morten Welinder's avatar Morten Welinder Committed by Alexandre Julliard

(PSDRV_AFMGetCharMetrics): Use unsigned chars (since isspace is used).

(PSDRV_AFMParse): Don't crash on missing font name. Use unsigned chars. Fix peculiar inconsistent indentation. Don't leak a FILE. Catch problematic files with no line feed in them. Don't mix characters and integers. Don't overrun the buffer.
parent ed6a7b4a
...@@ -34,8 +34,8 @@ FONTFAMILY *PSDRV_AFMFontList = NULL; ...@@ -34,8 +34,8 @@ FONTFAMILY *PSDRV_AFMFontList = NULL;
*/ */
static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp) static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
{ {
char line[256], valbuf[256]; unsigned char line[256], valbuf[256];
char *cp, *item, *value, *curpos, *endpos; unsigned char *cp, *item, *value, *curpos, *endpos;
int i; int i;
AFMMETRICS *metric; AFMMETRICS *metric;
...@@ -63,7 +63,7 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp) ...@@ -63,7 +63,7 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
while(isspace(*value)) while(isspace(*value))
value++; value++;
cp = endpos = strchr(value, ';'); cp = endpos = strchr(value, ';');
if (!cp) { ERR("missing ;, failed.\n"); return; } if (!cp) { ERR("missing ;, failed. [%s]\n", line); return; }
while(isspace(*--cp)) while(isspace(*--cp))
; ;
memcpy(valbuf, value, cp - value + 1); memcpy(valbuf, value, cp - value + 1);
...@@ -126,11 +126,12 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp) ...@@ -126,11 +126,12 @@ static void PSDRV_AFMGetCharMetrics(AFM *afm, FILE *fp)
static AFM *PSDRV_AFMParse(char const *file) static AFM *PSDRV_AFMParse(char const *file)
{ {
FILE *fp; FILE *fp;
char buf[256]; unsigned char buf[256];
char *value; unsigned char *value;
AFM *afm; AFM *afm;
char *cp; unsigned char *cp;
int afmfile = 0; int afmfile = 0;
int c;
TRACE("parsing '%s'\n", file); TRACE("parsing '%s'\n", file);
...@@ -146,31 +147,29 @@ static AFM *PSDRV_AFMParse(char const *file) ...@@ -146,31 +147,29 @@ static AFM *PSDRV_AFMParse(char const *file)
} }
cp = buf; cp = buf;
while ( ( *cp = fgetc ( fp ) ) != EOF ) { while ( ( c = fgetc ( fp ) ) != EOF ) {
if ( *cp == '\r' || *cp == '\n' || cp - buf == sizeof(buf)-1 ) { *cp = c;
if ( cp == buf ) if ( *cp == '\r' || *cp == '\n' || cp - buf == sizeof(buf)-2 ) {
continue; if ( cp == buf )
*(cp+1)='\0'; continue;
} *(cp+1)='\0';
else { }
cp ++; else {
continue; cp ++;
} continue;
}
cp = buf + strlen(buf); cp = buf + strlen(buf);
do { do {
*cp = '\0'; *cp = '\0';
cp--; cp--;
} while(cp > buf && isspace(*cp)); } while(cp > buf && isspace(*cp));
cp = buf; cp = buf;
if ( afmfile == 0 && strncmp ( buf, "StartFontMetrics", 16 ) ) { if ( afmfile == 0 && strncmp ( buf, "StartFontMetrics", 16 ) )
HeapFree ( PSDRV_Heap, 0, afm ); break;
return NULL; afmfile = 1;
}
else {
afmfile = 1;
}
value = strchr(buf, ' '); value = strchr(buf, ' ');
if(value) if(value)
...@@ -276,8 +275,15 @@ static AFM *PSDRV_AFMParse(char const *file) ...@@ -276,8 +275,15 @@ static AFM *PSDRV_AFMParse(char const *file)
} }
fclose(fp); fclose(fp);
if(afm->FontName == NULL) if (afmfile == 0) {
HeapFree ( PSDRV_Heap, 0, afm );
return NULL;
}
if(afm->FontName == NULL) {
WARN("%s contains no FontName.\n", file); WARN("%s contains no FontName.\n", file);
afm->FontName = HEAP_strdupA(PSDRV_Heap, 0, "nofont");
}
if(afm->FullName == NULL) if(afm->FullName == NULL)
afm->FullName = HEAP_strdupA(PSDRV_Heap, 0, afm->FontName); afm->FullName = HEAP_strdupA(PSDRV_Heap, 0, afm->FontName);
if(afm->FamilyName == NULL) if(afm->FamilyName == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment