Skip to contentSkip to conversation

selinuxfs: use scnprinft to get real length in sel_read_class

PATCH Superseded liuyang34 3 participants 3 messages Jan 6, 2020 – Jan 9, 2020 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

liuyang34

author
#1 lore raw

PATCH 1/1 selinuxfs: use scnprinft to get real length in sel_read_class

as the return value of snprintf maybe over the size of TMPBUFLEN, use scnprintf to instead of it

---
 security/selinux/selinuxfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/selinuxfs.c +1 -1
index ee94fa4..977c32d 100644
@@ -1672,7 +1672,7 @@ static ssize_t sel_read_class(struct file *file, char __user *buf,
 {
 	unsigned long ino = file_inode(file)->i_ino;
 	char res[TMPBUFLEN];
-	ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
+	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
 	return simple_read_from_buffer(buf, count, ppos, res, len);
 }
 
Signature · 1 line
2.7.4
#2 lore raw
Quoted 2 lines · On 1/5/20 8:56 PM, liuyang34 wrote:

as the return value of snprintf maybe over the size of TMPBUFLEN, use scnprintf to instead of it

Is there a reason you didn't make the same change to sel_read_perm()?

Quoted 20 lines
---
  security/selinux/selinuxfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/selinuxfs.c +1 -1
index ee94fa4..977c32d 100644
@@ -1672,7 +1672,7 @@ static ssize_t sel_read_class(struct file *file, char __user *buf,
  {
  	unsigned long ino = file_inode(file)->i_ino;
  	char res[TMPBUFLEN];
-	ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
+	ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
  	return simple_read_from_buffer(buf, count, ppos, res, len);
  }
 
#3 lore raw

Re: [PATCH] selinuxfs: use scnprintf to get real length in sel_read_class

In reply to liuyang34
Quoted 2 lines

as the return value of snprintf maybe over the size of TMPBUFLEN, use scnprintf to instead of it

Please improve your commit message.

Quoted 1 line
Signed-off-by liuyang34 …

Will this information need also an adjustment for the desired specification of a real name?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=b07f636fca1c8fbba124b0082487c0b3890a0e0c#n458

Regards,
Markus