Repository: angr/angr

Issue:
ZeroDivisionError when performing Propagator analysis
<!--
*Disclaimer:
The angr suite is maintained by a small team of volunteers.
While we cannot guarantee any timeliness for fixes and enhancements, we will do our best.
For more real-time help with angr, from us and the community, join our [Slack.](http://angr.io/invite/)*
-->
---

**Describe the bug.**
<!--
Please include a clear and concise description of what the bug is.
-->
When I trying to perform propagator analysis against a mips32el binary, it throw ZeroDivisionError exception.
Here is the test script:
```python
import angr
import IPython

example = "./httpd"

proj = angr.Project(example, auto_load_libs=False)

cfg = proj.analyses.CFGFast(show_progressbar=True)

func = cfg.functions[0x43b26c]

prop = proj.analyses.Propagator(func=func, only_consts=True)
replacements=prop.replacements

IPython.embed()
```
And the traceback:
```
Traceback (most recent call last):
  File "/mnt/data/karonte_proj/angr-dev/angr/test.py", line 12, in <module>
    prop = proj.analyses.Propagator(func=func, only_consts=True)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
    oself.__init__(*args, **kwargs)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/propagator.py", line 355, in __init__
    self._analyze()
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/propagator.py", line 495, in _analyze
    self._analysis_core_graph()
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/forward_analysis/forward_analysis.py", line 240, in _analysis_core_graph
    changed, output_state = self._run_on_node(n, job_state)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/propagator.py", line 403, in _run_on_node
    load_callback=self._load_callback, fail_fast=self._fail_fast)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/engine_base.py", line 27, in process
    self._process(state, None, block=kwargs.pop('block', None))
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/engine_vex.py", line 25, in _process
    super()._process(state, successors, block=block, whitelist=whitelist, **kwargs)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 83, in _process
    self._process_Stmt(whitelist=whitelist)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 104, in _process_Stmt
    self._handle_Stmt(stmt)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 132, in _handle_Stmt
    getattr(self, handler)(stmt)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/engine_vex.py", line 102, in _handle_WrTmp
    super()._handle_WrTmp(stmt)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 138, in _handle_WrTmp
    data = self._expr(stmt.data)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/analyses/propagator/engine_vex.py", line 45, in _expr
    v = super()._expr(expr)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 170, in _expr
    return getattr(self, handler)(expr)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 263, in _handle_Binop
    return getattr(self, handler)(expr)
  File "/mnt/data/karonte_proj/angr-dev/angr/angr/engines/light/engine.py", line 422, in _handle_Div
    return expr_0 // expr_1
ZeroDivisionError: integer division or modulo by zero

Process finished with exit code 1

```

**Environment Information.**
<!--
Many common issues are caused by problems with the local Python environment.
Before submitting, double-check that your versions of all modules in the angr suite (angr, cle, pyvex, ...) are up to date.
Please include the output of `python -m angr.misc.bug_report` here.
-->
```
angr environment report
=============================
Date: 2020-07-17 11:34:11.000442
Running in virtual environment at /home/test/.virtualenvs/karonte3
Platform: linux-x86_64
Python version: 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0]
######## angr #########
Python found it in /mnt/data/karonte_proj/angr-dev/angr/angr
Pip version angr 8.20.6.8
Git info:
        Current commit f44d989b05e5b6825e8d7d100868dc85a8356bef from branch master
        Checked out from remote origin: https://github.com/angr/angr-dev
######## ailment #########
Python found it in /mnt/data/karonte_proj/angr-dev/ailment/ailment
Pip version ailment 8.20.7.6
Git info:
        Current commit 3490c152766fe7df04dfa922fa58c03166676944 from branch master
        Checked out from remote origin: https://github.com/angr/ailment
######## cle #########
Python found it in /mnt/data/karonte_proj/angr-dev/cle/cle
Pip version cle 8.20.7.6
Git info:
        Current commit 36f7a0e140fc96bb644f21d0c13d60713d6ae025 from branch master
        Checked out from remote origin: https://github.com/angr/cle
######## pyvex #########
Python found it in /home/test/.virtualenvs/karonte3/lib/python3.6/site-packages/pyvex
Pip version pyvex 8.20.7.6
Couldn't find git info
######## claripy #########
Python found it in /mnt/data/karonte_proj/angr-dev/claripy/claripy
Pip version claripy 8.20.7.6
Git info:
        Current commit f2c1998731efca4838a4edb9dec77e0424c5f691 from branch master
        Checked out from remote origin: https://github.com/angr/claripy
######## archinfo #########
Python found it in /mnt/data/karonte_proj/angr-dev/archinfo/archinfo
Pip version archinfo 8.20.7.6
Git info:
        Current commit c48e4b40a6a1f7edab6bd0597fe3d5dda1d73e62 from branch master
        Checked out from remote origin: https://github.com/angr/archinfo
######## z3 #########
Python found it in /home/test/.virtualenvs/karonte3/lib/python3.6/site-packages/z3
Pip version z3-solver 4.8.8.0
Couldn't find git info
######## unicorn #########
Python found it in /home/test/.virtualenvs/karonte3/lib/python3.6/site-packages/unicorn
Pip version unicorn 1.0.2rc4
Couldn't find git info
######### Native Module Info ##########
angr: <CDLL '/mnt/data/karonte_proj/angr-dev/angr/angr/lib/angr_native.so', handle 219b540 at 0x7fdbe4d63c88>
unicorn: <CDLL '/home/test/.virtualenvs/karonte3/lib/python3.6/site-packages/unicorn/lib/libunicorn.so', handle 1345d20 at 0x7fdbe3d19be0>
pyvex: <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7fdbe4c84668>
```

**To Reproduce.**
<!--
Please include *both a script to reproduce the crash, and attach the binary used, if possible*
-->
Here is the binary used in the testcase.
[httpd.zip](https://github.com/angr/angr/files/4935609/httpd.zip)


**Additional context.**
<!--
Add any other context about the problem here.
-->



Discussion:

Resolving patch:
diff --git a/angr/engines/light/engine.py b/angr/engines/light/engine.py
--- a/angr/engines/light/engine.py
+++ b/angr/engines/light/engine.py
@@ -423,6 +423,9 @@ def _handle_Div(self, expr):
         except TypeError as e:
             self.l.warning(e)
             return None
+        except ZeroDivisionError as e:
+            self.l.warning(e)
+            return None
 
     def _handle_Xor(self, expr):
         arg0, arg1 = expr.args


Test patch: