diff options
| author | Wei Yongjun <yongjun_wei@trendmicro.com.cn> | 2012-09-02 09:21:46 -0400 |
|---|---|---|
| committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-09-24 18:17:24 -0400 |
| commit | 52da2449e10039d3bb04c598d24cb1a34530b716 (patch) | |
| tree | ec8f1ede07653b09902edb4670efaa2b4cc9269d /net/nfc | |
| parent | 33e5971358c37851137b264f815977507c016fac (diff) | |
NFC: Fix possible LLCP memory leak
nfc_llcp_build_tlv() malloced the memory and should be free in
nfc_llcp_build_gb() after used, and the same in the error handling
case, otherwise it will cause memory leak.
spatch with a semantic match is used to found this problem.
(http://coccinelle.lip6.fr/)
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc')
| -rw-r--r-- | net/nfc/llcp/llcp.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/net/nfc/llcp/llcp.c b/net/nfc/llcp/llcp.c index 6f368412ffd2..90ef4a176819 100644 --- a/net/nfc/llcp/llcp.c +++ b/net/nfc/llcp/llcp.c | |||
| @@ -426,6 +426,7 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local) | |||
| 426 | u8 *miux_tlv, miux_length; | 426 | u8 *miux_tlv, miux_length; |
| 427 | __be16 miux; | 427 | __be16 miux; |
| 428 | u8 gb_len = 0; | 428 | u8 gb_len = 0; |
| 429 | int ret = 0; | ||
| 429 | 430 | ||
| 430 | version = LLCP_VERSION_11; | 431 | version = LLCP_VERSION_11; |
| 431 | version_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &version, | 432 | version_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &version, |
| @@ -450,8 +451,8 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local) | |||
| 450 | gb_len += ARRAY_SIZE(llcp_magic); | 451 | gb_len += ARRAY_SIZE(llcp_magic); |
| 451 | 452 | ||
| 452 | if (gb_len > NFC_MAX_GT_LEN) { | 453 | if (gb_len > NFC_MAX_GT_LEN) { |
| 453 | kfree(version_tlv); | 454 | ret = -EINVAL; |
| 454 | return -EINVAL; | 455 | goto out; |
| 455 | } | 456 | } |
| 456 | 457 | ||
| 457 | gb_cur = local->gb; | 458 | gb_cur = local->gb; |
| @@ -471,12 +472,15 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local) | |||
| 471 | memcpy(gb_cur, miux_tlv, miux_length); | 472 | memcpy(gb_cur, miux_tlv, miux_length); |
| 472 | gb_cur += miux_length; | 473 | gb_cur += miux_length; |
| 473 | 474 | ||
| 475 | local->gb_len = gb_len; | ||
| 476 | |||
| 477 | out: | ||
| 474 | kfree(version_tlv); | 478 | kfree(version_tlv); |
| 475 | kfree(lto_tlv); | 479 | kfree(lto_tlv); |
| 480 | kfree(wks_tlv); | ||
| 481 | kfree(miux_tlv); | ||
| 476 | 482 | ||
| 477 | local->gb_len = gb_len; | 483 | return ret; |
| 478 | |||
| 479 | return 0; | ||
| 480 | } | 484 | } |
| 481 | 485 | ||
| 482 | u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len) | 486 | u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len) |
