Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
96f77cb6a6
commit
e4e3208180
@ -251,7 +251,7 @@ void *up_backuplog_alloc(const char *name, size_t size)
|
||||
{
|
||||
if (0 == header->entry[index].size)
|
||||
{
|
||||
strncpy(header->entry[index].name, name, CXD56_LOG_ENTRY_NAME);
|
||||
strlcpy(header->entry[index].name, name, CXD56_LOG_ENTRY_NAME);
|
||||
header->entry[index].addr = (void *)((uint32_t)header +
|
||||
(allocated << AREASHIFT));
|
||||
header->entry[index].size = size;
|
||||
|
@ -758,8 +758,8 @@ static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir,
|
||||
}
|
||||
|
||||
entry->d_type = DTYPE_FILE;
|
||||
strncpy(entry->d_name, g_powermg_procfs_dir[procfs->index],
|
||||
strlen(g_powermg_procfs_dir[procfs->index])+1);
|
||||
strlcpy(entry->d_name, g_powermg_procfs_dir[procfs->index],
|
||||
sizeof(entry->d_name));
|
||||
procfs->index++;
|
||||
|
||||
return OK;
|
||||
|
@ -269,14 +269,12 @@ static ssize_t dvfs_write(struct file *filep, const char *buffer,
|
||||
int n;
|
||||
int tmp;
|
||||
|
||||
n = MIN(buflen, DVFS_LINELEN - 1);
|
||||
strncpy(line, buffer, n);
|
||||
line[n] = '\0';
|
||||
n = MIN(buflen, DVFS_LINELEN);
|
||||
strlcpy(line, buffer, n);
|
||||
|
||||
n = strcspn(line, " ");
|
||||
n = MIN(n, sizeof(cmd) - 1);
|
||||
strncpy(cmd, line, n);
|
||||
cmd[n] = '\0';
|
||||
n = MIN(n, sizeof(cmd));
|
||||
strlcpy(cmd, line, n);
|
||||
|
||||
if (0 == strcmp(cmd, "cur_freq"))
|
||||
{
|
||||
|
@ -1177,7 +1177,7 @@ int amebaz_wl_initialize(unsigned char mode)
|
||||
|
||||
else
|
||||
{
|
||||
strncpy(wrq.ifr_name, "wlan0", IFNAMSIZ);
|
||||
strlcpy(wrq.ifr_name, "wlan0", IFNAMSIZ);
|
||||
wrq.u.mode = IW_MODE_INFRA;
|
||||
return amebaz_wl_set_mode(gp_wlan_dev[0], &wrq);
|
||||
}
|
||||
|
@ -1610,8 +1610,7 @@ bl602_net_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
strncpy(passphrase, (char *)ext->key, ext->key_len);
|
||||
passphrase[ext->key_len] = 0;
|
||||
strlcpy(passphrase, (char *)ext->key, ext->key_len + 1);
|
||||
|
||||
wifi_mgmr_sta_passphr_set(passphrase);
|
||||
kmm_free(passphrase);
|
||||
|
@ -606,8 +606,7 @@ int esp32c3_partition_init(void)
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(label, (char *)info->label, PARTITION_LABEL_LEN);
|
||||
label[PARTITION_LABEL_LEN] = '\0';
|
||||
strlcpy(label, (char *)info->label, sizeof(label));
|
||||
sprintf(path, "%s%s", path_base, label);
|
||||
|
||||
finfo("INFO: [label]: %s\n", label);
|
||||
|
@ -1159,8 +1159,8 @@ static int mpfs_rptun_init(const char *shmemname, const char *cpuname)
|
||||
#endif
|
||||
|
||||
dev->rptun.ops = &g_mpfs_rptun_ops;
|
||||
strncpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE);
|
||||
strncpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE);
|
||||
strlcpy(dev->cpuname, cpuname, sizeof(dev->cpuname));
|
||||
strlcpy(dev->shmemname, shmemname, sizeof(dev->shmemname));
|
||||
list_add_tail(&g_dev_list, &dev->node);
|
||||
|
||||
ret = rptun_initialize(&dev->rptun);
|
||||
|
@ -604,8 +604,7 @@ int esp32_partition_init(void)
|
||||
break;
|
||||
}
|
||||
|
||||
strncpy(label, (char *)info->label, PARTITION_LABEL_LEN);
|
||||
label[PARTITION_LABEL_LEN] = 0;
|
||||
strlcpy(label, (char *)info->label, sizeof(label));
|
||||
sprintf(path, "%s%s", path_base, label);
|
||||
|
||||
finfo("INFO: [label]: %s\n", label);
|
||||
|
@ -136,7 +136,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
offset = len - sizeof(pdump->info.filename);
|
||||
}
|
||||
|
||||
strncpy(pdump->info.filename, (char *)&filename[offset],
|
||||
strlcpy(pdump->info.filename, (char *)&filename[offset],
|
||||
sizeof(pdump->info.filename));
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
/* Save Context */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(pdump->info.name, rtcb->name, sizeof(pdump->info.name));
|
||||
#endif
|
||||
|
||||
pdump->info.pid = rtcb->pid;
|
||||
|
@ -364,7 +364,7 @@ static int lpc17_40_getstatus(struct ubxmdm_lower * lower,
|
||||
|
||||
for (i = 0; i < UBXMDM_REGISTER_COUNT; i++)
|
||||
{
|
||||
strncpy(status->register_values[i].name,
|
||||
strlcpy(status->register_values[i].name,
|
||||
lpc17_40_ubxmdm_name_pins[i].name,
|
||||
3);
|
||||
status->register_values[i].val =
|
||||
|
@ -408,7 +408,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
offset = len - sizeof(pdump->info.filename);
|
||||
}
|
||||
|
||||
strncpy(pdump->info.filename, (char *)&filename[offset],
|
||||
strlcpy(pdump->info.filename, (char *)&filename[offset],
|
||||
sizeof(pdump->info.filename));
|
||||
}
|
||||
|
||||
@ -423,7 +423,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
/* Save Context */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(pdump->info.name, rtcb->name, sizeof(pdump->info.name));
|
||||
#endif
|
||||
|
||||
pdump->info.pid = rtcb->pid;
|
||||
|
@ -408,7 +408,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
offset = len - sizeof(pdump->info.filename);
|
||||
}
|
||||
|
||||
strncpy(pdump->info.filename, (char *)&filename[offset],
|
||||
strlcpy(pdump->info.filename, (char *)&filename[offset],
|
||||
sizeof(pdump->info.filename));
|
||||
}
|
||||
|
||||
@ -423,7 +423,7 @@ void board_crashdump(uintptr_t currentsp, void *tcb,
|
||||
/* Save Context */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(pdump->info.name, rtcb->name, sizeof(pdump->info.name));
|
||||
#endif
|
||||
|
||||
pdump->info.pid = rtcb->pid;
|
||||
|
@ -362,7 +362,7 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
|
||||
offset = len - sizeof(pdump->info.filename);
|
||||
}
|
||||
|
||||
strncpy((char *)pdump->info.filename, (char *)&filename[offset],
|
||||
strlcpy((char *)pdump->info.filename, (char *)&filename[offset],
|
||||
sizeof(pdump->info.filename));
|
||||
}
|
||||
|
||||
@ -377,7 +377,7 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
|
||||
/* Save Context */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(pdump->info.name, rtcb->name, sizeof(pdump->info.name));
|
||||
#endif
|
||||
|
||||
pdump->info.pid = rtcb->pid;
|
||||
|
@ -360,7 +360,7 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
|
||||
offset = len - sizeof(pdump->info.filename);
|
||||
}
|
||||
|
||||
strncpy((char *)pdump->info.filename, (char *)&filename[offset],
|
||||
strlcpy((char *)pdump->info.filename, (char *)&filename[offset],
|
||||
sizeof(pdump->info.filename));
|
||||
}
|
||||
|
||||
@ -375,7 +375,7 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
|
||||
/* Save Context */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
strncpy(pdump->info.name, rtcb->name, CONFIG_TASK_NAME_SIZE);
|
||||
strlcpy(pdump->info.name, rtcb->name, sizeof(pdump->info.name));
|
||||
#endif
|
||||
|
||||
pdump->info.pid = rtcb->pid;
|
||||
|
@ -425,7 +425,8 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
info->sectorsize = priv->blocksize;
|
||||
info->startsector = priv->firstblock;
|
||||
|
||||
strncpy(info->parent, priv->parent->name, NAME_MAX);
|
||||
strlcpy(info->parent, priv->parent->name,
|
||||
sizeof(info->parent));
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
@ -5928,10 +5928,9 @@ static int smart_fsck_directory(FAR struct smart_struct_s *dev,
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS_INFO
|
||||
strncpy(entryname,
|
||||
strlcpy(entryname,
|
||||
(const char *) (cur + sizeof(struct smart_entry_header_s)),
|
||||
dev->namesize);
|
||||
entryname[dev->namesize] = '\0';
|
||||
sizeof(entryname));
|
||||
finfo("Check entry (name=%s flags=%02x logsector=%02x)\n",
|
||||
entryname, entry->flags, entry->firstsector);
|
||||
#endif
|
||||
@ -6210,7 +6209,7 @@ int smart_initialize(int minor, FAR struct mtd_dev_s *mtd,
|
||||
dev->namesize = CONFIG_SMARTFS_MAXNAMLEN;
|
||||
if (partname)
|
||||
{
|
||||
strncpy(dev->partname, partname, SMART_PARTNAME_SIZE);
|
||||
strlcpy(dev->partname, partname, SMART_PARTNAME_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -322,7 +322,7 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid,
|
||||
|
||||
client->pid = pid;
|
||||
client->event = *event;
|
||||
strncpy(client->intf, intf, IFNAMSIZ + 1);
|
||||
strlcpy(client->intf, intf, IFNAMSIZ + 1);
|
||||
client->intf[IFNAMSIZ] = '\0';
|
||||
|
||||
/* Attach/re-attach the PHY interrupt */
|
||||
|
@ -1009,7 +1009,7 @@ static int tun_dev_init(FAR struct tun_device_s *priv,
|
||||
|
||||
if (devfmt)
|
||||
{
|
||||
strncpy(priv->dev.d_ifname, devfmt, IFNAMSIZ);
|
||||
strlcpy(priv->dev.d_ifname, devfmt, IFNAMSIZ);
|
||||
}
|
||||
|
||||
/* Register the device with the OS so that socket IOCTLs can be performed */
|
||||
@ -1342,7 +1342,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
tun->free_tuns &= ~(1 << intf);
|
||||
|
||||
priv = filep->f_priv;
|
||||
strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ);
|
||||
strlcpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ);
|
||||
tundev_unlock(tun);
|
||||
|
||||
return OK;
|
||||
|
@ -190,7 +190,7 @@ static void noteram_record_taskname(pid_t pid, const char *name)
|
||||
ti->size = tilen;
|
||||
ti->pid[0] = pid & 0xff;
|
||||
ti->pid[1] = (pid >> 8) & 0xff;
|
||||
strncpy(ti->name, name, namelen + 1);
|
||||
strlcpy(ti->name, name, namelen + 1);
|
||||
g_noteram_taskname.buffer_used += tilen;
|
||||
}
|
||||
#endif
|
||||
@ -748,7 +748,7 @@ static int noteram_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
taskname = noteram_get_taskname(param->pid);
|
||||
if (taskname != NULL)
|
||||
{
|
||||
strncpy(param->taskname, taskname, CONFIG_TASK_NAME_SIZE + 1);
|
||||
strlcpy(param->taskname, taskname, CONFIG_TASK_NAME_SIZE + 1);
|
||||
param->taskname[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
ret = 0;
|
||||
}
|
||||
|
@ -1919,7 +1919,7 @@ static int video_queryctrl(FAR struct v4l2_queryctrl *ctrl)
|
||||
ctrl->step = ext_ctrl.step;
|
||||
ctrl->default_value = ext_ctrl.default_value;
|
||||
ctrl->flags = ext_ctrl.flags;
|
||||
strncpy(ctrl->name, ext_ctrl.name, sizeof(ctrl->name));
|
||||
strlcpy(ctrl->name, ext_ctrl.name, sizeof(ctrl->name));
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -1942,7 +1942,7 @@ static void set_parameter_name(uint32_t id, char *name)
|
||||
|
||||
/* copy size = 32 is due to V4L2 specification. */
|
||||
|
||||
strncpy(name, g_video_parameter_name[cnt].name, 32);
|
||||
strlcpy(name, g_video_parameter_name[cnt].name, 32);
|
||||
}
|
||||
|
||||
static int video_query_ext_ctrl(FAR struct v4l2_query_ext_ctrl *attr)
|
||||
@ -1975,7 +1975,7 @@ static int video_query_ext_ctrl(FAR struct v4l2_query_ext_ctrl *attr)
|
||||
attr->maximum = VIDEO_SCENE_MAX - 1;
|
||||
attr->step = 1;
|
||||
attr->default_value = 0;
|
||||
strncpy(attr->name, "Scene Mode", 32);
|
||||
strlcpy(attr->name, "Scene Mode", 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2945,11 +2945,11 @@ static int gs2200m_ioctl_ifreq(FAR struct gs2200m_dev_s *dev,
|
||||
memcpy(&in[0], &dev->net_dev.d_ipaddr, sizeof(in[0]));
|
||||
memcpy(&in[1], &dev->net_dev.d_netmask, sizeof(in[1]));
|
||||
memcpy(&in[2], &dev->net_dev.d_draddr, sizeof(in[2]));
|
||||
strncpy(addr[0], inet_ntoa_r(in[0], inetaddr, sizeof(inetaddr)),
|
||||
strlcpy(addr[0], inet_ntoa_r(in[0], inetaddr, sizeof(inetaddr)),
|
||||
sizeof(addr[0]));
|
||||
strncpy(addr[1], inet_ntoa_r(in[1], inetaddr, sizeof(inetaddr)),
|
||||
strlcpy(addr[1], inet_ntoa_r(in[1], inetaddr, sizeof(inetaddr)),
|
||||
sizeof(addr[1]));
|
||||
strncpy(addr[2], inet_ntoa_r(in[2], inetaddr, sizeof(inetaddr)),
|
||||
strlcpy(addr[2], inet_ntoa_r(in[2], inetaddr, sizeof(inetaddr)),
|
||||
sizeof(addr[2]));
|
||||
|
||||
gs2200m_set_addresses(dev, addr[0], addr[1], addr[2]);
|
||||
|
@ -885,7 +885,7 @@ static int procfs_readdir(FAR struct inode *mountpt,
|
||||
level1->subdirlen + 1];
|
||||
level1->lastlen = strcspn(name, "/");
|
||||
level1->lastread = name;
|
||||
strncpy(entry->d_name, name, level1->lastlen);
|
||||
strlcpy(entry->d_name, name, level1->lastlen);
|
||||
|
||||
/* Some of the search entries contain '**' wildcards. When we
|
||||
* report the entry name, we must remove this wildcard search
|
||||
|
@ -529,8 +529,7 @@ int smartfs_finddirentry(struct smartfs_mountpt_s *fs,
|
||||
goto errout;
|
||||
}
|
||||
|
||||
strncpy(fs->fs_workbuffer, segment, seglen);
|
||||
fs->fs_workbuffer[seglen] = '\0';
|
||||
strlcpy(fs->fs_workbuffer, segment, seglen + 1);
|
||||
|
||||
/* Search for "." and ".." as segment names */
|
||||
|
||||
@ -669,10 +668,8 @@ int smartfs_finddirentry(struct smartfs_mountpt_s *fs,
|
||||
kmm_malloc(fs->fs_llformat.namesize + 1);
|
||||
}
|
||||
|
||||
memset(direntry->name, 0,
|
||||
fs->fs_llformat.namesize + 1);
|
||||
strncpy(direntry->name, entry->name,
|
||||
fs->fs_llformat.namesize);
|
||||
strlcpy(direntry->name, entry->name,
|
||||
fs->fs_llformat.namesize + 1);
|
||||
direntry->datlen = 0;
|
||||
|
||||
/* Scan the file's sectors to calculate the length
|
||||
@ -1056,7 +1053,7 @@ int smartfs_createentry(FAR struct smartfs_mountpt_s *fs,
|
||||
entry->utc = time(NULL);
|
||||
#endif
|
||||
memset(entry->name, 0, fs->fs_llformat.namesize);
|
||||
strncpy(entry->name, filename, fs->fs_llformat.namesize);
|
||||
strlcpy(entry->name, filename, fs->fs_llformat.namesize);
|
||||
|
||||
/* Now write the new entry to the parent directory sector */
|
||||
|
||||
@ -1102,7 +1099,7 @@ int smartfs_createentry(FAR struct smartfs_mountpt_s *fs,
|
||||
}
|
||||
|
||||
memset(direntry->name, 0, fs->fs_llformat.namesize + 1);
|
||||
strncpy(direntry->name, filename, fs->fs_llformat.namesize);
|
||||
strlcpy(direntry->name, filename, fs->fs_llformat.namesize);
|
||||
|
||||
ret = OK;
|
||||
|
||||
|
@ -1392,7 +1392,7 @@ int spiffs_fobj_create(FAR struct spiffs_s *fs,
|
||||
#ifdef CONFIG_SPIFFS_LEADING_SLASH
|
||||
objndx_hdr.name[0] = '/';
|
||||
#endif
|
||||
strncpy((char *)objndx_hdr.name + SPIFFS_LEADING_SLASH_SIZE,
|
||||
strlcpy((char *)objndx_hdr.name + SPIFFS_LEADING_SLASH_SIZE,
|
||||
(const char *)name,
|
||||
CONFIG_SPIFFS_NAME_MAX);
|
||||
|
||||
@ -1481,7 +1481,7 @@ int spiffs_fobj_update_ndxhdr(FAR struct spiffs_s *fs,
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
strncpy((FAR char *)objhdr->name + SPIFFS_LEADING_SLASH_SIZE,
|
||||
strlcpy((FAR char *)objhdr->name + SPIFFS_LEADING_SLASH_SIZE,
|
||||
(FAR const char *)name,
|
||||
CONFIG_SPIFFS_NAME_MAX);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ static int userfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
req->oflags = oflags;
|
||||
req->mode = mode;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_OPEN_REQUEST_S(pathlen + 1), 0,
|
||||
@ -1115,7 +1115,7 @@ static int userfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
req = (FAR struct userfs_opendir_request_s *)priv->iobuffer;
|
||||
req->req = USERFS_REQ_OPENDIR;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_OPENDIR_REQUEST_S(pathlen + 1), 0,
|
||||
@ -1696,7 +1696,7 @@ static int userfs_unlink(FAR struct inode *mountpt,
|
||||
req = (FAR struct userfs_unlink_request_s *)priv->iobuffer;
|
||||
req->req = USERFS_REQ_UNLINK;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_UNLINK_REQUEST_S(pathlen + 1), 0,
|
||||
@ -1783,7 +1783,7 @@ static int userfs_mkdir(FAR struct inode *mountpt,
|
||||
req->req = USERFS_REQ_MKDIR;
|
||||
req->mode = mode;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_MKDIR_REQUEST_S(pathlen + 1), 0,
|
||||
@ -1869,7 +1869,7 @@ static int userfs_rmdir(FAR struct inode *mountpt,
|
||||
req = (FAR struct userfs_rmdir_request_s *)priv->iobuffer;
|
||||
req->req = USERFS_REQ_RMDIR;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_RMDIR_REQUEST_S(pathlen + 1), 0,
|
||||
@ -1960,8 +1960,8 @@ static int userfs_rename(FAR struct inode *mountpt,
|
||||
req->req = USERFS_REQ_RENAME;
|
||||
req->newoffset = oldpathlen;
|
||||
|
||||
strncpy(req->oldrelpath, oldrelpath, oldpathlen);
|
||||
strncpy(&req->oldrelpath[oldpathlen], newrelpath, newpathlen);
|
||||
strlcpy(req->oldrelpath, oldrelpath, oldpathlen);
|
||||
strlcpy(&req->oldrelpath[oldpathlen], newrelpath, newpathlen);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_RENAME_REQUEST_S(oldpathlen, newpathlen),
|
||||
@ -2047,7 +2047,7 @@ static int userfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
req = (FAR struct userfs_stat_request_s *)priv->iobuffer;
|
||||
req->req = USERFS_REQ_STAT;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_STAT_REQUEST_S(pathlen + 1), 0,
|
||||
@ -2139,7 +2139,7 @@ static int userfs_chstat(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
req->buf = *buf;
|
||||
req->flags = flags;
|
||||
|
||||
strncpy(req->relpath, relpath, priv->mxwrite);
|
||||
strlcpy(req->relpath, relpath, priv->mxwrite);
|
||||
|
||||
nsent = psock_sendto(&priv->psock, priv->iobuffer,
|
||||
SIZEOF_USERFS_CHSTAT_REQUEST_S(pathlen + 1), 0,
|
||||
|
@ -234,8 +234,7 @@ int nftw(FAR const char *path, nftw_cb_t fn, int fdlimit, int flags)
|
||||
{
|
||||
char pathbuf[PATH_MAX + 1];
|
||||
|
||||
strncpy(pathbuf, path, PATH_MAX);
|
||||
pathbuf[PATH_MAX] = '\0';
|
||||
strlcpy(pathbuf, path, sizeof(pathbuf));
|
||||
|
||||
return do_nftw(pathbuf, fn, fdlimit, flags, 0);
|
||||
}
|
||||
|
@ -84,26 +84,23 @@ int uname(FAR struct utsname *name)
|
||||
|
||||
/* Copy the strings. Assure that each is NUL terminated. */
|
||||
|
||||
strncpy(name->sysname, "NuttX", SYS_NAMELEN);
|
||||
strlcpy(name->sysname, "NuttX", sizeof(name->sysname));
|
||||
|
||||
/* Get the hostname */
|
||||
|
||||
ret = gethostname(name->nodename, HOST_NAME_MAX);
|
||||
name->nodename[HOST_NAME_MAX - 1] = '\0';
|
||||
|
||||
strncpy(name->release, CONFIG_VERSION_STRING, SYS_NAMELEN);
|
||||
name->release[SYS_NAMELEN - 1] = '\0';
|
||||
strlcpy(name->release, CONFIG_VERSION_STRING, sizeof(name->release));
|
||||
|
||||
#if defined(__DATE__) && defined(__TIME__)
|
||||
snprintf(name->version, VERSION_NAMELEN, "%s %s %s",
|
||||
CONFIG_VERSION_BUILD, __DATE__, __TIME__);
|
||||
#else
|
||||
strncpy(name->version, CONFIG_VERSION_BUILD, VERSION_NAMELEN);
|
||||
strlcpy(name->version, CONFIG_VERSION_BUILD, sizeof(name->version));
|
||||
#endif
|
||||
name->version[VERSION_NAMELEN - 1] = '\0';
|
||||
|
||||
strncpy(name->machine, CONFIG_ARCH, SYS_NAMELEN);
|
||||
name->machine[SYS_NAMELEN - 1] = '\0';
|
||||
strlcpy(name->machine, CONFIG_ARCH, sizeof(name->machine));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ int getifaddrs(FAR struct ifaddrs **addrs)
|
||||
}
|
||||
|
||||
myaddrs->addrs.ifa_name = myaddrs->name;
|
||||
strncpy(myaddrs->name, req.lifr_name, IF_NAMESIZE);
|
||||
strlcpy(myaddrs->name, req.lifr_name, IF_NAMESIZE);
|
||||
|
||||
myaddrs->addrs.ifa_flags = flags;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ FAR char *if_indextoname(unsigned int ifindex, FAR char *ifname)
|
||||
req.ifr_ifindex = ifindex;
|
||||
if (ioctl(sockfd, SIOCGIFNAME, (unsigned long)&req) >= 0)
|
||||
{
|
||||
strncpy(ifname, req.ifr_name, IF_NAMESIZE);
|
||||
strlcpy(ifname, req.ifr_name, IF_NAMESIZE);
|
||||
close(sockfd);
|
||||
return ifname;
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ out_copyname:
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
strncpy(dest, g_lo_hostname, buflen);
|
||||
strlcpy(dest, g_lo_hostname, buflen);
|
||||
host->h_name = dest;
|
||||
|
||||
return 0;
|
||||
|
@ -195,7 +195,7 @@ static int lib_numeric_address(FAR const char *name,
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
strncpy(ptr, name, buflen);
|
||||
strlcpy(ptr, name, buflen);
|
||||
|
||||
/* Set the address to h_name */
|
||||
|
||||
@ -278,7 +278,7 @@ static int lib_localhost(FAR const char *name, FAR struct hostent_s *host,
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
strncpy(dest, name, buflen);
|
||||
strlcpy(dest, name, buflen);
|
||||
|
||||
/* Set the address to h_name */
|
||||
|
||||
@ -408,7 +408,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent_s *host,
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
strncpy(ptr, name, buflen);
|
||||
strlcpy(ptr, name, buflen);
|
||||
|
||||
/* Set the address to h_name */
|
||||
|
||||
@ -545,7 +545,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent_s *host,
|
||||
/* And copy name */
|
||||
|
||||
DEBUGASSERT(buflen >= namelen + 1);
|
||||
strncpy(ptr, name, buflen);
|
||||
strlcpy(ptr, name, buflen);
|
||||
|
||||
/* Set the address to h_name */
|
||||
|
||||
|
@ -96,7 +96,7 @@ int posix_spawn_file_actions_addopen(
|
||||
entry->fd = fd;
|
||||
entry->oflags = oflags;
|
||||
entry->mode = mode;
|
||||
strncpy(entry->path, path, len + 1);
|
||||
strlcpy(entry->path, path, len + 1);
|
||||
|
||||
/* And add it to the file action list */
|
||||
|
||||
|
@ -337,8 +337,7 @@ int lib_vscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
|
||||
{
|
||||
for (tc = fmt; isdigit(fmt_char(fmt)); fmt++)
|
||||
;
|
||||
strncpy(tmp, tc, fmt - tc);
|
||||
tmp[fmt - tc] = '\0';
|
||||
strlcpy(tmp, tc, fmt - tc + 1);
|
||||
width = atoi(tmp);
|
||||
fmt--;
|
||||
}
|
||||
|
@ -54,6 +54,6 @@ int strerror_r(int errnum, FAR char *buf, size_t buflen)
|
||||
FAR const char *errstr = strerror(errnum);
|
||||
|
||||
DEBUGASSERT(buf != NULL);
|
||||
strncpy(buf, errstr, buflen);
|
||||
strlcpy(buf, errstr, buflen);
|
||||
return OK;
|
||||
}
|
||||
|
@ -1613,13 +1613,12 @@ static int tzparse(FAR const char *name, FAR struct state_s *sp,
|
||||
}
|
||||
|
||||
cp = sp->chars;
|
||||
strncpy(cp, stdname, stdlen);
|
||||
stdlen += 1;
|
||||
strlcpy(cp, stdname, stdlen);
|
||||
cp += stdlen;
|
||||
*cp++ = '\0';
|
||||
if (dstlen != 0)
|
||||
{
|
||||
strncpy(cp, dstname, dstlen);
|
||||
*(cp + dstlen) = '\0';
|
||||
strlcpy(cp, dstname, dstlen + 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -111,7 +111,7 @@ int gethostname(FAR char *name, size_t namelen)
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
strncpy(name, g_hostname, namelen);
|
||||
strlcpy(name, g_hostname, namelen);
|
||||
leave_critical_section(flags);
|
||||
|
||||
return 0;
|
||||
|
@ -190,7 +190,7 @@ static int icmpv6_send_message(FAR struct net_driver_s *dev, bool advertise)
|
||||
|
||||
/* Remember the routing device name */
|
||||
|
||||
strncpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname,
|
||||
strlcpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname,
|
||||
IFNAMSIZ);
|
||||
|
||||
/* Allocate resources to receive a callback. This and the following
|
||||
|
@ -264,7 +264,7 @@ int icmpv6_neighbor(const net_ipv6addr_t ipaddr)
|
||||
|
||||
/* Remember the routing device name */
|
||||
|
||||
strncpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname,
|
||||
strlcpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname,
|
||||
IFNAMSIZ);
|
||||
|
||||
/* Now loop, testing if the address mapping is in the Neighbor Table and
|
||||
|
@ -173,8 +173,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
||||
client->lc_peer = conn;
|
||||
#endif /* CONFIG_NET_LOCAL_SCM */
|
||||
|
||||
strncpy(conn->lc_path, client->lc_path, UNIX_PATH_MAX - 1);
|
||||
conn->lc_path[UNIX_PATH_MAX - 1] = '\0';
|
||||
strlcpy(conn->lc_path, client->lc_path, sizeof(conn->lc_path));
|
||||
conn->lc_instance_id = client->lc_instance_id;
|
||||
|
||||
/* Open the server-side write-only FIFO. This should not
|
||||
|
@ -92,8 +92,7 @@ int psock_local_bind(FAR struct socket *psock,
|
||||
|
||||
/* Copy the path into the connection structure */
|
||||
|
||||
strncpy(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX - 1);
|
||||
conn->lc_path[UNIX_PATH_MAX - 1] = '\0';
|
||||
strlcpy(conn->lc_path, unaddr->sun_path, sizeof(conn->lc_path));
|
||||
conn->lc_instance_id = -1;
|
||||
}
|
||||
}
|
||||
|
@ -306,9 +306,8 @@ int psock_local_connect(FAR struct socket *psock,
|
||||
|
||||
client->lc_type = conn->lc_type;
|
||||
client->lc_proto = conn->lc_proto;
|
||||
strncpy(client->lc_path, unaddr->sun_path,
|
||||
UNIX_PATH_MAX - 1);
|
||||
client->lc_path[UNIX_PATH_MAX - 1] = '\0';
|
||||
strlcpy(client->lc_path, unaddr->sun_path,
|
||||
sizeof(client->lc_path));
|
||||
client->lc_instance_id = local_generate_instance_id();
|
||||
|
||||
/* The client is now bound to an address */
|
||||
|
@ -200,7 +200,7 @@ static int ifconf_ipv6_callback(FAR struct net_driver_s *dev, FAR void *arg)
|
||||
* transferred is returned in lifc_len.
|
||||
*/
|
||||
|
||||
strncpy(req->lifr_name, dev->d_ifname, IFNAMSIZ);
|
||||
strlcpy(req->lifr_name, dev->d_ifname, IFNAMSIZ);
|
||||
|
||||
inaddr->sin6_family = AF_INET6;
|
||||
inaddr->sin6_port = 0;
|
||||
|
@ -516,7 +516,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
|
||||
/* Copy the network statistics directory entry */
|
||||
|
||||
entry->d_type = DTYPE_FILE;
|
||||
strncpy(entry->d_name, "stat", NAME_MAX + 1);
|
||||
strlcpy(entry->d_name, "stat", sizeof(entry->d_name));
|
||||
}
|
||||
else
|
||||
#ifdef CONFIG_NET_MLD
|
||||
@ -525,7 +525,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
|
||||
/* Copy the MLD directory entry */
|
||||
|
||||
entry->d_type = DTYPE_FILE;
|
||||
strncpy(entry->d_name, "mld", NAME_MAX + 1);
|
||||
strlcpy(entry->d_name, "mld", sizeof(entry->d_name));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -536,7 +536,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
|
||||
/* Copy the network statistics directory entry */
|
||||
|
||||
entry->d_type = DTYPE_DIRECTORY;
|
||||
strncpy(entry->d_name, "route", NAME_MAX + 1);
|
||||
strlcpy(entry->d_name, "route", sizeof(entry->d_name));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -584,7 +584,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
|
||||
/* Copy the device statistics file entry */
|
||||
|
||||
entry->d_type = DTYPE_FILE;
|
||||
strncpy(entry->d_name, dev->d_ifname, NAME_MAX + 1);
|
||||
strlcpy(entry->d_name, dev->d_ifname, sizeof(entry->d_name));
|
||||
}
|
||||
|
||||
/* Set up the next directory entry offset. NOTE that we could use the
|
||||
|
@ -715,7 +715,7 @@ static int route_readdir(FAR struct fs_dirent_s *dir,
|
||||
/* Save the filename and file type */
|
||||
|
||||
entry->d_type = DTYPE_FILE;
|
||||
strncpy(entry->d_name, dname, NAME_MAX + 1);
|
||||
strlcpy(entry->d_name, dname, sizeof(entry->d_name));
|
||||
|
||||
/* Set up the next directory entry offset. NOTE that we could use the
|
||||
* standard f_pos instead of our own private index.
|
||||
|
@ -483,8 +483,7 @@ static void nxtask_setup_name(FAR struct task_tcb_s *tcb,
|
||||
{
|
||||
/* Copy the name into the TCB */
|
||||
|
||||
strncpy(tcb->cmn.name, name, CONFIG_TASK_NAME_SIZE);
|
||||
tcb->cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
|
||||
strlcpy(tcb->cmn.name, name, sizeof(tcb->cmn.name));
|
||||
}
|
||||
#else
|
||||
# define nxtask_setup_name(t,n)
|
||||
|
Loading…
Reference in New Issue
Block a user