Unverified Commit 7aab0ca5 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!12344 of: module: prevent NULL pointer dereference in vsnprintf()

parents 81d3c729 d08b6a56
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -226,6 +226,14 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
	if ((!dev) || (!dev->of_node))
		return -ENODEV;

	/*
	 * Prevent a kernel oops in vsnprintf() -- it only allows passing a
	 * NULL ptr when the length is also 0. Also filter out the negative
	 * lengths...
	 */
	if ((len > 0 && !str) || len < 0)
		return -EINVAL;

	/* Name & Type */
	/* %p eats all alphanum characters, so %c must be used here */
	csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T',