-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix insecureAPI, NonLocalizedStringChecker, NewDeleteLeaks macOS clang errors #31333
Conversation
@@ -220,7 +220,12 @@ | |||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project]; | |||
[viewController loadView]; | |||
[engine setViewController:viewController]; | |||
|
|||
// Unit test localization is unnecessary. | |||
// NOLINTBEGIN(clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: User-facing text should use localized string macro [clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,-warnings-as-errors]
@@ -31,7 +31,7 @@ - (instancetype)initWithEvent:(const FlutterKeyEvent*)event | |||
if (event->character != nullptr) { | |||
size_t len = strlen(event->character); | |||
char* character = new char[len + 1]; | |||
strcpy(character, event->character); | |||
strlcpy(character, event->character, sizeof(character)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter for this unit test, but can't hurt.
error: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors]
NSCAssert(!IsControlCharacter(keyLabelChar) && !IsUnprintableKey(keyLabelChar), | ||
@"Unexpected control or unprintable keylabel 0x%x", keyLabelChar); | ||
NSCAssert(keyLabelChar <= 0x10FFFF, @"Out of range keylabel 0x%x", keyLabelChar); | ||
character = keyLabelChar; | ||
} | ||
delete[] keyLabel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: Potential leak of memory pointed to by 'keyLabel' [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]
@@ -291,4 +296,4 @@ | |||
EXPECT_EQ([native_text_field.stringValue isEqualToString:@"textfield"], YES); | |||
} | |||
|
|||
} // flutter::testing | |||
} // namespace flutter::testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a warning, but fix it anyway:
warning: namespace 'flutter::testing' ends with an unrecognized comment [google-readability-namespace-comments]
@@ -31,7 +31,7 @@ void SleepFor(TimeDelta duration) { | |||
|
|||
void EpsilonRandomSleep() { | |||
TimeDelta duration = | |||
TimeDelta::FromMilliseconds(static_cast<unsigned>(rand()) % 20u); | |||
TimeDelta::FromMilliseconds(static_cast<unsigned>(arc4random()) % 20u); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter for these unit tests, but can't hurt.
error: Function 'rand' is obsolete because it implements a poor random number generator. Use 'arc4random' instead [clang-analyzer-security.insecureAPI.rand,-warnings-as-errors]
@@ -4,6 +4,7 @@ | |||
|
|||
#include "flutter/fml/synchronization/waitable_event.h" | |||
|
|||
#include <stdlib.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why isn't this include
sufficient?
../../flutter/fml/synchronization/waitable_event_unittest.cc:35:57: error: use of undeclared identifier 'arc4random'
TimeDelta::FromMilliseconds(static_cast<unsigned>(arc4random()) % 20u);
Closing in favor of Zach's fixes in #31291. |
Fix some of the clang-tidy errors in the macOS embedder found in #31291 (comment).
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.