Fix NULL pointer issue with Word2000 empty attributes.

This appears to be an issue with Word2000 handling of empty attributes.

A reproduction case can be seen here:

```
$ cat test.html
<html xmlns:o="urn:schemas-microsoft-com:office:office">
    <body>
        <table>
            <img class="" />
        </table>
    </body>
</html>

$ ./tidy --tidy-mark no --word-2000 yes test.html
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 3 column 1 - Warning: <img> isn't allowed in <table> elements
line 2 column 1 - Info: <table> previously mentioned
line 1 column 57 - Warning: inserting missing 'title' element
line 3 column 1 - Warning: <img> lacks "alt" attribute
line 3 column 1 - Warning: <img> lacks "src" attribute
line 2 column 1 - Warning: trimming empty <table>
line 1 column 1 - Warning: <html> proprietary attribute "xmlns:o"
[2]    52405 segmentation fault  ./tidy --tidy-mark no --word-2000 yes test.html
```

This was called from 6f2fb6e0e7/src/clean.c (L1710).

(It is technically undefined behaviour to call strncmp with `NULL` pointers however).
This commit is contained in:
Michael Thorpe 2017-08-24 17:24:42 +01:00
parent 951a65bdcf
commit 52465c6142
No known key found for this signature in database
GPG key ID: FDBE1D1375CBCBE9

View file

@ -126,6 +126,13 @@ int TY_(tmbstrcasecmp)( ctmbstr s1, ctmbstr s2 )
int TY_(tmbstrncmp)( ctmbstr s1, ctmbstr s2, uint n ) int TY_(tmbstrncmp)( ctmbstr s1, ctmbstr s2, uint n )
{ {
if (s1 == NULL || s2 == NULL)
{
if (s1 == s2)
return 0;
return (s1 == NULL ? -1 : 1);
}
uint c; uint c;
while ((c = (byte)*s1) == (byte)*s2) while ((c = (byte)*s1) == (byte)*s2)