diff options
author | Hubert Kowalski <h.kowalski@samsung.com> | 2021-10-19 16:59:24 +0200 |
---|---|---|
committer | Hubert Kowalski <h.kowalski@samsung.com> | 2021-10-22 10:02:04 +0200 |
commit | 1275ffae299f66e3c67bd8fce9ecbac3982393c7 (patch) | |
tree | 40ba044b916ce464aa90cd521cfede12bfbcd912 | |
parent | ed3f365db479cbea9785656c4795a2058c5f7f1e (diff) | |
download | libusbg-tizen_8.0.tar.gz libusbg-tizen_8.0.tar.bz2 libusbg-tizen_8.0.zip |
Fix erroneous calloc NULL checktizen_9.0_m2_releasetizen_8.0_m2_releasetizen_7.0_m2_releasesubmit/tizen_base/20211104.091630submit/tizen/20211104.092607submit/tizen/20211103.072537accepted/tizen/unified/20211108.181449accepted/tizen/9.0/unified/20241030.233404accepted/tizen/8.0/unified/20231005.095130accepted/tizen/7.0/unified/hotfix/20221116.111042accepted/tizen/7.0/unified/20221110.063039tizen_9.0tizen_8.0tizen_7.0_hotfixtizen_7.0tizenaccepted/tizen_unifiedaccepted/tizen_9.0_unifiedaccepted/tizen_8.0_unifiedaccepted/tizen_7.0_unified_hotfixaccepted/tizen_7.0_unified
This commit fixes potential issue caused by bad allocation.
Which causes operating on unallocated memory.
Change-Id: I4d5291bde4504fce1ed1e13d596d83270f38bf40
-rw-r--r-- | src/usbg.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -1810,19 +1810,19 @@ static int usbg_get_strs_langs_by_path(const char *epath, const char *name, n = snprintf(spath, sizeof(spath), "%s/%s/%s", epath, name, STRINGS_DIR); if (n >= sizeof(spath)) { - ret = USBG_ERROR_PATH_TOO_LONG; - goto out; + return USBG_ERROR_PATH_TOO_LONG; } n = scandir(spath, &dent, file_select, alphasort); if (n < 0) { - ret = usbg_translate_error(errno); - goto out; + return usbg_translate_error(errno); } buf = calloc(n + 1, sizeof(*buf)); - if (!buf) + if (buf == NULL) { ret = USBG_ERROR_NO_MEM; + goto out; + } /* Keep the buffer 0 terminated */ buf[n] = 0; @@ -1837,15 +1837,17 @@ static int usbg_get_strs_langs_by_path(const char *epath, const char *name, else ret = USBG_ERROR_OTHER_ERROR; } - free(dent[i]); } - free(dent); if (ret != USBG_SUCCESS) free(buf); else *langs = buf; out: + for (i = 0; i < n; i++) { + free(dent[i]); + } + free(dent); return ret; } |