Skip to content

Commit 9368373

Browse files
lauxinwwenlingz
authored andcommitted
tools: acrn-crashlog: check the pointer after getting sender
get_sender_from_name would return NULL if the name of sender is not configured in acrnprobe.xml. This patch check the return value of it. Tracked-On: #1024 Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com> Reviewed-by: Huang Yonghua <yonghua.huang@intel.com> Acked-by: Chen Gang <gang.c.chen@intel.com>
1 parent 2973db7 commit 9368373

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/acrn-crashlog/acrnprobe/sender.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static void telemd_send_info(struct event_t *e)
463463

464464
static void telemd_send_uptime(void)
465465
{
466-
struct sender_t *telemd;
466+
struct sender_t *telemd = get_sender_by_name("telemd");
467467
struct uptime_t *uptime;
468468
char *class;
469469
char boot_time[UPTIME_SIZE];
@@ -472,12 +472,14 @@ static void telemd_send_uptime(void)
472472
static int uptime_hours;
473473
static int loop_uptime_event = 1;
474474

475+
if (!telemd)
476+
return;
477+
475478
ret = get_uptime_string(boot_time, &hours);
476479
if (ret < 0) {
477480
LOGE("cannot get uptime - %s\n", strerror(-ret));
478481
return;
479482
}
480-
telemd = get_sender_by_name("telemd");
481483
uptime = telemd->uptime;
482484
uptime_hours = atoi(uptime->eventhours);
483485
if (hours / uptime_hours >= loop_uptime_event) {
@@ -505,12 +507,14 @@ static void telemd_send_uptime(void)
505507

506508
static void telemd_send_reboot(void)
507509
{
508-
struct sender_t *telemd;
510+
struct sender_t *telemd = get_sender_by_name("telemd");
509511
char *class;
510512
char reason[REBOOT_REASON_SIZE];
511513
int ret;
512514

513-
telemd = get_sender_by_name("telemd");
515+
if (!telemd)
516+
return;
517+
514518
if (swupdated(telemd)) {
515519
char *content;
516520

0 commit comments

Comments
 (0)