mirror of https://github.com/torvalds/linux.git
s390/cio: Use scnprintf() instead of sprintf()
Use scnprintf() instead of sprintf() for those cases where the destination is an array and the size of the array is known at compile time. This prevents theoretical buffer overflows, but also avoids that people again and again spend time to figure out if the code is actually safe. Reviewed-by: Jan Polensky <japo@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
This commit is contained in:
parent
6850221116
commit
ba06238bbe
|
|
@ -41,7 +41,7 @@ static void __ccwgroup_remove_symlinks(struct ccwgroup_device *gdev)
|
|||
char str[16];
|
||||
|
||||
for (i = 0; i < gdev->count; i++) {
|
||||
sprintf(str, "cdev%d", i);
|
||||
scnprintf(str, sizeof(str), "cdev%d", i);
|
||||
sysfs_remove_link(&gdev->dev.kobj, str);
|
||||
sysfs_remove_link(&gdev->cdev[i]->dev.kobj, "group_device");
|
||||
}
|
||||
|
|
@ -249,12 +249,12 @@ static int __ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
|
|||
}
|
||||
}
|
||||
for (i = 0; i < gdev->count; i++) {
|
||||
sprintf(str, "cdev%d", i);
|
||||
scnprintf(str, sizeof(str), "cdev%d", i);
|
||||
rc = sysfs_create_link(&gdev->dev.kobj,
|
||||
&gdev->cdev[i]->dev.kobj, str);
|
||||
if (rc) {
|
||||
while (i--) {
|
||||
sprintf(str, "cdev%d", i);
|
||||
scnprintf(str, sizeof(str), "cdev%d", i);
|
||||
sysfs_remove_link(&gdev->dev.kobj, str);
|
||||
}
|
||||
for (i = 0; i < gdev->count; i++)
|
||||
|
|
|
|||
|
|
@ -111,8 +111,9 @@ static int s390_vary_chpid(struct chp_id chpid, int on)
|
|||
char dbf_text[15];
|
||||
int status;
|
||||
|
||||
sprintf(dbf_text, on?"varyon%x.%02x":"varyoff%x.%02x", chpid.cssid,
|
||||
chpid.id);
|
||||
scnprintf(dbf_text, sizeof(dbf_text),
|
||||
on ? "varyon%x.%02x" : "varyoff%x.%02x",
|
||||
chpid.cssid, chpid.id);
|
||||
CIO_TRACE_EVENT(2, dbf_text);
|
||||
|
||||
status = chp_get_status(chpid);
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ void chsc_chp_offline(struct chp_id chpid)
|
|||
struct chp_link link;
|
||||
char dbf_txt[15];
|
||||
|
||||
sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
|
||||
scnprintf(dbf_txt, sizeof(dbf_txt), "chpr%x.%02x", chpid.cssid, chpid.id);
|
||||
CIO_TRACE_EVENT(2, dbf_txt);
|
||||
|
||||
if (chp_get_status(chpid) <= 0)
|
||||
|
|
@ -284,11 +284,11 @@ static void s390_process_res_acc(struct chp_link *link)
|
|||
{
|
||||
char dbf_txt[15];
|
||||
|
||||
sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
|
||||
scnprintf(dbf_txt, sizeof(dbf_txt), "accpr%x.%02x", link->chpid.cssid,
|
||||
link->chpid.id);
|
||||
CIO_TRACE_EVENT( 2, dbf_txt);
|
||||
if (link->fla != 0) {
|
||||
sprintf(dbf_txt, "fla%x", link->fla);
|
||||
scnprintf(dbf_txt, sizeof(dbf_txt), "fla%x", link->fla);
|
||||
CIO_TRACE_EVENT( 2, dbf_txt);
|
||||
}
|
||||
/* Wait until previous actions have settled. */
|
||||
|
|
@ -757,7 +757,7 @@ void chsc_chp_online(struct chp_id chpid)
|
|||
struct chp_link link;
|
||||
char dbf_txt[15];
|
||||
|
||||
sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
|
||||
scnprintf(dbf_txt, sizeof(dbf_txt), "cadd%x.%02x", chpid.cssid, chpid.id);
|
||||
CIO_TRACE_EVENT(2, dbf_txt);
|
||||
|
||||
if (chp_get_status(chpid) != 0) {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
|
|||
if (cio_update_schib(sch))
|
||||
return -ENODEV;
|
||||
|
||||
sprintf(dbf_text, "no%s", dev_name(&sch->dev));
|
||||
scnprintf(dbf_text, sizeof(dbf_text), "no%s", dev_name(&sch->dev));
|
||||
CIO_TRACE_EVENT(0, dbf_text);
|
||||
CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
|
|||
cdev->private->dev_id.devno, sch->schid.ssid,
|
||||
sch->schid.sch_no,
|
||||
scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw));
|
||||
sprintf(dbf_text, "chk%x", sch->schid.sch_no);
|
||||
scnprintf(dbf_text, sizeof(dbf_text), "chk%x", sch->schid.sch_no);
|
||||
CIO_TRACE_EVENT(0, dbf_text);
|
||||
CIO_HEX_EVENT(0, irb, sizeof(struct irb));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue