Date: Sun, 19 Jul 2015 11:13:15 +0000 From: "emaste (Ed Maste)" <phabric-noreply@FreeBSD.org> To: freebsd-toolchain@freebsd.org Subject: [Differential] [Updated, 62 lines] D2338: readelf: avoid division by zero for files with invalid sh_entsize Message-ID: <7c59257489905e00b12a6a1519c33dd8@localhost.localdomain> In-Reply-To: <differential-rev-PHID-DREV-qcsywqhy33xvasn2kx4a-req@FreeBSD.org> References: <differential-rev-PHID-DREV-qcsywqhy33xvasn2kx4a-req@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--b1_7c59257489905e00b12a6a1519c33dd8 Content-Type: text/plain; charset = "utf-8" Content-Transfer-Encoding: 8bit emaste updated this revision to Diff 7069. emaste added a comment. This revision now requires review to proceed. Add a `get_ent_count` helper to check for 0 entsize instead of expanding the check inline everywhere. CHANGES SINCE LAST UPDATE https://reviews.freebsd.org/D2338?vs=4930&id=7069 REVISION DETAIL https://reviews.freebsd.org/D2338 AFFECTED FILES contrib/elftoolchain/readelf/readelf.c EMAIL PREFERENCES https://reviews.freebsd.org/settings/panel/emailpreferences/ To: emaste, brooks Cc: brooks, freebsd-toolchain-list --b1_7c59257489905e00b12a6a1519c33dd8 Content-Type: text/x-patch; charset=utf-8; name="D2338.7069.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="D2338.7069.patch" ZGlmZiAtLWdpdCBhL2NvbnRyaWIvZWxmdG9vbGNoYWluL3JlYWRlbGYvcmVhZGVsZi5jIGIvY29u dHJpYi9lbGZ0b29sY2hhaW4vcmVhZGVsZi9yZWFkZWxmLmMKLS0tIGEvY29udHJpYi9lbGZ0b29s Y2hhaW4vcmVhZGVsZi9yZWFkZWxmLmMKKysrIGIvY29udHJpYi9lbGZ0b29sY2hhaW4vcmVhZGVs Zi9yZWFkZWxmLmMKQEAgLTI3LDYgKzI3LDcgQEAKICNpbmNsdWRlIDxzeXMvcGFyYW0uaD4KICNp bmNsdWRlIDxzeXMvcXVldWUuaD4KICNpbmNsdWRlI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JCSAgICAiQ2hlY2tzdW0iLCAiVmVyc2lvbiIsICJGbGFncyIpOwogCQlm b3IgKGogPSAwOyAodWludDY0X3QpIGogPCBzLT5zeiAvIHMtPmVudHNpemU7IGorKykgewpAQCAt NDM5OCw3ICs0NDI5LDcgQEAKIGR1bXBfbWlwc19yZWdpbmZvKHN0cnVjdCByZWFkZWxmICpyZSwg c3RydWN0IHNlY3Rpb24gKnMpCiB7CiAJRWxmX0RhdGEgKmQ7Ci0JaW50IGVsZmVycjsKKwlpbnQg ZWxmZXJyLCBsZW47CiAKIAkodm9pZCkgZWxmX2Vycm5vKCk7CiAJaWYgKChkID0gZWxmX3Jhd2Rh dGEocy0+c2NuLCBOVUxMKSkgPT0gTlVMTCkgewpAQCAtNDQxMCw5ICs0NDQxLDEwIEBACiAJfQog CWlmIChkLT5kX3NpemUgPD0gMCkKIAkJcmV0dXJuOworCWlmICghZ2V0X2VudF9jb3VudChzLCAm bGVuKSkKKwkJcmV0dXJuOwogCi0JcHJpbnRmKCJcblNlY3Rpb24gJyVzJyBjb250YWlucyAlanUg ZW50cmllczpcbiIsIHMtPm5hbWUsCi0JICAgIHMtPnN6IC8gcy0+ZW50c2l6ZSk7CisJcHJpbnRm KCJcblNlY3Rpb24gJyVzJyBjb250YWlucyAlZCBlbnRyaWVzOlxuIiwgcy0+bmFtZSwgbGVuKTsK IAlkdW1wX21pcHNfb2RrX3JlZ2luZm8ocmUsIGQtPmRfYnVmLCBkLT5kX3NpemUpOwogfQogCgo= --b1_7c59257489905e00b12a6a1519c33dd8--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7c59257489905e00b12a6a1519c33dd8>