Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c771d06e authored by Hardik Arya's avatar Hardik Arya Committed by Gerrit - the friendly Code Review server
Browse files

diag: Use strlcpy/strlcat properly



Currently strlcpy/strlcat are used like strncpy/strncat
in diag driver. The patch corrects the use of strlcpy
and strncpy by passing size as size of destination buffer.

Change-Id: If8f5376413a6f23405e918469c83568c6c73b552
Signed-off-by: default avatarHardik Arya <harya@codeaurora.org>
parent c1f61aae
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -636,8 +636,8 @@ int diag_usb_register(int id, int ctxt, struct diag_mux_ops *ops)
	INIT_WORK(&(ch->read_done_work), usb_read_done_work_fn);
	INIT_WORK(&(ch->connect_work), usb_connect_work_fn);
	INIT_WORK(&(ch->disconnect_work), usb_disconnect_work_fn);
	strlcpy(wq_name, "DIAG_USB_", DIAG_USB_STRING_SZ);
	strlcat(wq_name, ch->name, sizeof(ch->name));
	strlcpy(wq_name, "DIAG_USB_", sizeof(wq_name));
	strlcat(wq_name, ch->name, sizeof(wq_name));
	ch->usb_wq = create_singlethread_workqueue(wq_name);
	if (!ch->usb_wq)
		goto err;
+1 −1
Original line number Diff line number Diff line
@@ -4292,7 +4292,7 @@ static int __init diagchar_init(void)
	pr_debug("diagchar initializing ..\n");
	driver->num = 1;
	driver->name = ((void *)driver) + sizeof(struct diagchar_dev);
	strlcpy(driver->name, "diag", 4);
	strlcpy(driver->name, "diag", 5);
	/* Get major number from kernel and initialize */
	ret = alloc_chrdev_region(&dev, driver->minor_start,
				    driver->num, driver->name);
+3 −3
Original line number Diff line number Diff line
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -176,8 +176,8 @@ int diagfwd_bridge_register(int id, int ctxt, struct diag_remote_dev_ops *ops)
		if (!ch->dci_read_buf)
			return -ENOMEM;
		ch->dci_read_len = 0;
		strlcpy(wq_name, "diag_dci_", 10);
		strlcat(wq_name, ch->name, sizeof(ch->name));
		strlcpy(wq_name, "diag_dci_", sizeof(wq_name));
		strlcat(wq_name, ch->name, sizeof(wq_name));
		INIT_WORK(&(ch->dci_read_work), bridge_dci_read_work_fn);
		ch->dci_wq = create_singlethread_workqueue(wq_name);
		if (!ch->dci_wq) {
+5 −3
Original line number Diff line number Diff line
@@ -845,6 +845,7 @@ int diag_add_diag_id_to_list(uint8_t diag_id, char *process_name,
	uint8_t pd_val, uint8_t peripheral)
{
	struct diag_id_tbl_t *new_item = NULL;
	int process_len = 0;

	if (!process_name || diag_id == 0) {
		DIAG_LOG(DIAG_DEBUG_PERIPHERALS,
@@ -857,7 +858,8 @@ int diag_add_diag_id_to_list(uint8_t diag_id, char *process_name,
	if (!new_item)
		return -ENOMEM;
	kmemleak_not_leak(new_item);
	new_item->process_name = kzalloc(strlen(process_name) + 1, GFP_KERNEL);
	process_len = strlen(process_name);
	new_item->process_name = kzalloc(process_len + 1, GFP_KERNEL);
	if (!new_item->process_name) {
		kfree(new_item);
		new_item = NULL;
@@ -867,7 +869,7 @@ int diag_add_diag_id_to_list(uint8_t diag_id, char *process_name,
	new_item->diag_id = diag_id;
	new_item->pd_val = pd_val;
	new_item->peripheral = peripheral;
	strlcpy(new_item->process_name, process_name, strlen(process_name) + 1);
	strlcpy(new_item->process_name, process_name, process_len + 1);
	INIT_LIST_HEAD(&new_item->link);
	mutex_lock(&driver->diag_id_mutex);
	list_add_tail(&new_item->link, &driver->diag_id_list);
@@ -969,7 +971,7 @@ static void process_diagid(uint8_t *buf, uint32_t len,
	ctrl_pkt.pkt_id = DIAG_CTRL_MSG_DIAGID;
	ctrl_pkt.version = 1;
	strlcpy((char *)&ctrl_pkt.process_name, process_name,
		strlen(process_name) + 1);
		sizeof(ctrl_pkt.process_name));
	ctrl_pkt.len = sizeof(ctrl_pkt.diag_id) + sizeof(ctrl_pkt.version) +
			strlen(process_name) + 1;
	err = diagfwd_write(peripheral, TYPE_CNTL, &ctrl_pkt, ctrl_pkt.len +
+2 −2
Original line number Diff line number Diff line
@@ -407,8 +407,8 @@ int diag_hsic_init(void)
		INIT_WORK(&(ch->read_work), hsic_read_work_fn);
		INIT_WORK(&(ch->open_work), hsic_open_work_fn);
		INIT_WORK(&(ch->close_work), hsic_close_work_fn);
		strlcpy(wq_name, "DIAG_HSIC_", DIAG_HSIC_STRING_SZ);
		strlcat(wq_name, ch->name, sizeof(ch->name));
		strlcpy(wq_name, "DIAG_HSIC_", sizeof(wq_name));
		strlcat(wq_name, ch->name, sizeof(wq_name));
		ch->hsic_wq = create_singlethread_workqueue(wq_name);
		if (!ch->hsic_wq)
			goto fail;
Loading