pstore: use snprintf
PATCH 1/3 pstore: use snprintf
No guarantees that the names will not exceed the
name buffer with future adjustments.
Signed-off-by Mark Salyzyn <[email protected]>
--- fs/pstore/inode.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/pstore/inode.c +11 -9
@@ -338,32 +338,34 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,switch (type) {case PSTORE_TYPE_DMESG : -sprintf (name,"dmesg-%s-%lld%s" , psname, id, +snprintf (name,sizeof (name),"dmesg-%s-%lld%s" , psname, id, compressed ?".enc.z" :"" );break ;case PSTORE_TYPE_CONSOLE : -sprintf (name,"console-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"console-%s-%lld" , psname, id);break ;case PSTORE_TYPE_FTRACE : -sprintf (name,"ftrace-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"ftrace-%s-%lld" , psname, id);break ;case PSTORE_TYPE_MCE : -sprintf (name,"mce-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"mce-%s-%lld" , psname, id);break ;case PSTORE_TYPE_PPC_RTAS : -sprintf (name,"rtas-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"rtas-%s-%lld" , psname, id);break ;case PSTORE_TYPE_PPC_OF : -sprintf (name,"powerpc-ofw-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"powerpc-ofw-%s-%lld" , psname, id);break ;case PSTORE_TYPE_PPC_COMMON : -sprintf (name,"powerpc-common-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"powerpc-common-%s-%lld" , + psname, id);break ;case PSTORE_TYPE_UNKNOWN : -sprintf (name,"unknown-%s-%lld" , psname, id); +snprintf (name,sizeof (name),"unknown-%s-%lld" , psname, id);break ;default : -sprintf (name,"type%d-%s-%lld" , type, psname, id); +snprintf (name,sizeof (name),"type%d-%s-%lld" , type, + psname, id);break ; }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Quoted 2 lines · Mark Salyzyn
No guarantees that the names will not exceed the
name buffer with future adjustments.
[]
fs/pstore/inode.c
Quoted 1 line
fs/pstore/inode.c +0
-0
[]
fs/pstore/inode.c int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count, · line 342
Quoted 7 lines
fs/pstore/inode.c +1
-1@@ -338,32 +338,34 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,switch (type) {case PSTORE_TYPE_DMESG : -sprintf (name,"dmesg-%s-%lld%s" , psname, id, +snprintf (name,sizeof (name),"dmesg-%s-%lld%s" , psname, id, compressed ?".enc.z" :"" );
scnprintf to ensure null termination?
(and maybe better written like)
scnprintf(name, sizeof(name), "dmesg-%s-%lld%s", psname, id, compressed ? ".enc.z" : "");