Re: [PATCH 1/3] pstore: use snprintf

From: Joe Perches
Date: Tue Jan 06 2015 - 12:20:55 EST


On Tue, 2015-01-06 at 09:15 -0800, Mark Salyzyn wrote:
> No guarantees that the names will not exceed the
> name buffer with future adjustments.
[]
> diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
[]
> @@ -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" : "");

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/