Skip to content

Commit

Permalink
md_is_autolink_email: Fix an off-by-one error.
Browse files Browse the repository at this point in the history
Fixes #100.
  • Loading branch information
mity committed Jan 5, 2020
1 parent 1a984d2 commit 561f52e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Fixes:
(This does not affect you unless you are on Windows and explicitly define
the macro when building MD4C.)

* [#100](https://github.com/mity/md4c/issues/100):
Fixed an off-by-one error in the maximal length limit of some segments
of e-mail addresses used in autolinks.


## Version 0.4.2

Expand Down
4 changes: 2 additions & 2 deletions md4c/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2900,7 +2900,7 @@ md_is_autolink_email(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end)
return FALSE;
off++;

/* Labels delimited with '.'; each label is sequence of 1 - 62 alnum
/* Labels delimited with '.'; each label is sequence of 1 - 63 alnum
* characters or '-', but '-' is not allowed as first or last char. */
label_len = 0;
while(off < max_end) {
Expand All @@ -2913,7 +2913,7 @@ md_is_autolink_email(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end)
else
break;

if(label_len > 62)
if(label_len > 63)
return FALSE;

off++;
Expand Down
17 changes: 16 additions & 1 deletion test/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ foo

### [Issue 97](https://github.com/mity/md4c/issues/97)


```````````````````````````````` example
*a **b c* d**
.
Expand All @@ -241,6 +240,22 @@ foo
````````````````````````````````


### [Issue 100](https://github.com/mity/md4c/issues/100)

```````````````````````````````` example
<foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123>
.
<p><a href="mailto:foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123">foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123</a></p>
````````````````````````````````

```````````````````````````````` example
<foo@123456789012345678901234567890123456789012345678901234567890123x.123456789012345678901234567890123456789012345678901234567890123>
.
<p>&lt;foo@123456789012345678901234567890123456789012345678901234567890123x.123456789012345678901234567890123456789012345678901234567890123&gt;</p>
````````````````````````````````
(Note the `x` here which turns it over the max. allowed length limit.)


## Code coverage

### `md_is_unicode_whitespace__()`
Expand Down

0 comments on commit 561f52e

Please sign in to comment.