Skip to content

Commit 62e0bee

Browse files
RovicnowYoyipopoaichuiniu
authored andcommitted
[BugFix][iOS]Fix App crash when nil is considered as NSString
[str UTF8String] will cause crash when str is nil, so we add judgement to avoid crash.
1 parent e71d4b8 commit 62e0bee

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

debug_router/iOS/DebugRouter.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ - (void)sendData:(NSString *)data
295295
}
296296

297297
- (void)sendAsync:(NSString *)message {
298+
if (message == nil) {
299+
return;
300+
}
298301
debugrouter::core::DebugRouterCore::GetInstance().SendAsync([message UTF8String]);
299302
}
300303

@@ -306,6 +309,9 @@ - (void)sendDataAsync:(NSString *)data
306309
WithType:(NSString *)type
307310
ForSession:(int)session
308311
WithMark:(int)mark {
312+
if (data == nil || type == nil) {
313+
return;
314+
}
309315
debugrouter::core::DebugRouterCore::GetInstance().SendDataAsync(
310316
[data UTF8String], [type UTF8String], session, mark, false);
311317
}
@@ -318,6 +324,9 @@ - (void)sendObjectAsync:(NSDictionary *)data
318324
WithType:(NSString *)type
319325
ForSession:(int)session
320326
WithMark:(int)mark {
327+
if (type == nil) {
328+
return;
329+
}
321330
NSError *error;
322331
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
323332
options:NSJSONWritingPrettyPrinted
@@ -426,10 +435,16 @@ - (BOOL)removeSessionHandler:(id<DebugRouterSessionHandler>)handler {
426435
}
427436

428437
- (BOOL)isValidSchema:(NSString *)schema {
438+
if (schema == nil) {
439+
return false;
440+
}
429441
return debugrouter::core::DebugRouterCore::GetInstance().IsValidSchema([schema UTF8String]);
430442
}
431443

432444
- (BOOL)handleSchema:(NSString *)schema {
445+
if (schema == nil) {
446+
return false;
447+
}
433448
LLogInfo(@"handleSchema: %@", schema);
434449
return debugrouter::core::DebugRouterCore::GetInstance().HandleSchema([schema UTF8String]);
435450
}
@@ -488,6 +503,9 @@ - (BOOL)getConfig:(NSString *)configKey withDefaultValue:(BOOL)defaultValue {
488503
}
489504

490505
- (void)setAppInfo:(nonnull NSString *)key withValue:(nonnull NSString *)value {
506+
if (key == nil || value == nil) {
507+
return;
508+
}
491509
debugrouter::core::DebugRouterCore::GetInstance().SetAppInfo([key UTF8String],
492510
[value UTF8String]);
493511
}

0 commit comments

Comments
 (0)