Closed Bug 1426989 Opened 6 years ago Closed 6 years ago

NS_strncmp returns incorrect resuts when the string is longer than aLen

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: emk, Assigned: emk)

Details

Attachments

(1 file, 1 obsolete file)

      No description provided.
Attached patch Fix NS_strncmp (obsolete) — Splinter Review
Assignee: nobody → VYV03354
Status: NEW → ASSIGNED
Attachment #8938784 - Flags: review?(erahm)
Attachment #8938784 - Attachment is obsolete: true
Attachment #8938784 - Flags: review?(erahm)
Attachment #8938786 - Flags: review?(erahm)
Comment on attachment 8938786 [details] [diff] [review]
1426989_NS_strncmp

Review of attachment 8938786 [details] [diff] [review]:
-----------------------------------------------------------------

r=me

::: xpcom/base/nsCRTGlue.cpp
@@ +116,5 @@
>      ++aStrB;
>      --aLen;
>    }
>  
> +  return aLen ? *aStrA != '\0' : 0;

Wow, good find!

::: xpcom/tests/gtest/TestCRT.cpp
@@ +47,5 @@
>    const char16_t* us1 = t1.get();
>    const char16_t* us2 = t2.get();
>  
> +  int u2, u2_n;
> +  // nsCRT::strncmp will cause buffer overrun

We should really fix that, bug 1427023 might be the right place.

@@ +89,5 @@
> +
> +  { "foo", "foobar", 3 },
> +  { "foobar", "foo", 3 },
> +  { "foobar", "foozap", 3 },
> +  { "foozap", "foobar", 3 },

Thanks for updating the tests.
Attachment #8938786 - Flags: review?(erahm) → review+
https://hg.mozilla.org/mozilla-central/rev/06d4983f64fe
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: