提交 74ea5f98 编写于 作者: R Ronnie Sahlberg 提交者: Steve French

cifs: replace snprintf with scnprintf

a trivial patch that replaces all use of snprintf with scnprintf.
scnprintf() is generally seen as a safer function to use than
snprintf for many use cases.

In our case, there is no actual difference between the two since we never
look at the return value. Thus we did not have any of the bugs that
scnprintf protects against and the patch does nothing.

However, for people reading our code it will be a receipt that we
have done our due dilligence and checked our code for this type of bugs.

See the presentation "Making C Less Dangerous In The Linux Kernel"
at this years LCA
Signed-off-by: NRonnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: NSteve French <stfrench@microsoft.com>
上级 68e2672f
...@@ -139,8 +139,8 @@ static int __cifs_reconnect_tcon(const struct nls_table *nlsc, ...@@ -139,8 +139,8 @@ static int __cifs_reconnect_tcon(const struct nls_table *nlsc,
return -ENOMEM; return -ENOMEM;
if (tcon->ipc) { if (tcon->ipc) {
snprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$", scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$",
tcon->ses->server->hostname); tcon->ses->server->hostname);
rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc);
goto out; goto out;
} }
...@@ -172,7 +172,7 @@ static int __cifs_reconnect_tcon(const struct nls_table *nlsc, ...@@ -172,7 +172,7 @@ static int __cifs_reconnect_tcon(const struct nls_table *nlsc,
continue; continue;
} }
snprintf(tree, MAX_TREE_SIZE, "\\%s", tgt); scnprintf(tree, MAX_TREE_SIZE, "\\%s", tgt);
rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc); rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc);
if (!rc) if (!rc)
......
...@@ -348,7 +348,7 @@ static int reconn_set_ipaddr(struct TCP_Server_Info *server) ...@@ -348,7 +348,7 @@ static int reconn_set_ipaddr(struct TCP_Server_Info *server)
cifs_dbg(FYI, "%s: failed to create UNC path\n", __func__); cifs_dbg(FYI, "%s: failed to create UNC path\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
snprintf(unc, len, "\\\\%s", server->hostname); scnprintf(unc, len, "\\\\%s", server->hostname);
rc = dns_resolve_server_name_to_ip(unc, &ipaddr); rc = dns_resolve_server_name_to_ip(unc, &ipaddr);
kfree(unc); kfree(unc);
...@@ -2775,7 +2775,7 @@ cifs_setup_ipc(struct cifs_ses *ses, struct smb_vol *volume_info) ...@@ -2775,7 +2775,7 @@ cifs_setup_ipc(struct cifs_ses *ses, struct smb_vol *volume_info)
if (tcon == NULL) if (tcon == NULL)
return -ENOMEM; return -ENOMEM;
snprintf(unc, sizeof(unc), "\\\\%s\\IPC$", ses->server->hostname); scnprintf(unc, sizeof(unc), "\\\\%s\\IPC$", ses->server->hostname);
/* cannot fail */ /* cannot fail */
nls_codepage = load_nls_default(); nls_codepage = load_nls_default();
...@@ -4203,7 +4203,7 @@ static int update_vol_info(const struct dfs_cache_tgt_iterator *tgt_it, ...@@ -4203,7 +4203,7 @@ static int update_vol_info(const struct dfs_cache_tgt_iterator *tgt_it,
new_unc = kmalloc(len, GFP_KERNEL); new_unc = kmalloc(len, GFP_KERNEL);
if (!new_unc) if (!new_unc)
return -ENOMEM; return -ENOMEM;
snprintf(new_unc, len, "\\%s", tgt); scnprintf(new_unc, len, "\\%s", tgt);
kfree(vol->UNC); kfree(vol->UNC);
vol->UNC = new_unc; vol->UNC = new_unc;
......
...@@ -103,9 +103,9 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len, ...@@ -103,9 +103,9 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
return rc; return rc;
} }
snprintf(md5_str2, sizeof(md5_str2), scnprintf(md5_str2, sizeof(md5_str2),
CIFS_MF_SYMLINK_MD5_FORMAT, CIFS_MF_SYMLINK_MD5_FORMAT,
CIFS_MF_SYMLINK_MD5_ARGS(md5_hash)); CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
if (strncmp(md5_str1, md5_str2, 17) != 0) if (strncmp(md5_str1, md5_str2, 17) != 0)
return -EINVAL; return -EINVAL;
...@@ -142,10 +142,10 @@ format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str) ...@@ -142,10 +142,10 @@ format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
return rc; return rc;
} }
snprintf(buf, buf_len, scnprintf(buf, buf_len,
CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT, CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT,
link_len, link_len,
CIFS_MF_SYMLINK_MD5_ARGS(md5_hash)); CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
ofs = CIFS_MF_SYMLINK_LINK_OFFSET; ofs = CIFS_MF_SYMLINK_LINK_OFFSET;
memcpy(buf + ofs, link_str, link_len); memcpy(buf + ofs, link_str, link_len);
......
...@@ -173,8 +173,8 @@ static int __smb2_reconnect(const struct nls_table *nlsc, ...@@ -173,8 +173,8 @@ static int __smb2_reconnect(const struct nls_table *nlsc,
return -ENOMEM; return -ENOMEM;
if (tcon->ipc) { if (tcon->ipc) {
snprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$", scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$",
tcon->ses->server->hostname); tcon->ses->server->hostname);
rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc); rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc);
goto out; goto out;
} }
...@@ -206,7 +206,7 @@ static int __smb2_reconnect(const struct nls_table *nlsc, ...@@ -206,7 +206,7 @@ static int __smb2_reconnect(const struct nls_table *nlsc,
continue; continue;
} }
snprintf(tree, MAX_TREE_SIZE, "\\%s", tgt); scnprintf(tree, MAX_TREE_SIZE, "\\%s", tgt);
rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc); rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc);
if (!rc) if (!rc)
......
...@@ -1550,7 +1550,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info) ...@@ -1550,7 +1550,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
int rc; int rc;
snprintf(name, MAX_NAME_LEN, "smbd_request_%p", info); scnprintf(name, MAX_NAME_LEN, "smbd_request_%p", info);
info->request_cache = info->request_cache =
kmem_cache_create( kmem_cache_create(
name, name,
...@@ -1566,7 +1566,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info) ...@@ -1566,7 +1566,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
if (!info->request_mempool) if (!info->request_mempool)
goto out1; goto out1;
snprintf(name, MAX_NAME_LEN, "smbd_response_%p", info); scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info);
info->response_cache = info->response_cache =
kmem_cache_create( kmem_cache_create(
name, name,
...@@ -1582,7 +1582,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info) ...@@ -1582,7 +1582,7 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
if (!info->response_mempool) if (!info->response_mempool)
goto out3; goto out3;
snprintf(name, MAX_NAME_LEN, "smbd_%p", info); scnprintf(name, MAX_NAME_LEN, "smbd_%p", info);
info->workqueue = create_workqueue(name); info->workqueue = create_workqueue(name);
if (!info->workqueue) if (!info->workqueue)
goto out4; goto out4;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册