res_fax: fix segfault on inactive "reserved" fax session
authorAlexei Gradinari <alex2grad@gmail.com>
Tue, 28 May 2019 20:35:17 +0000 (16:35 -0400)
committerGeorge Joseph <gjoseph@digium.com>
Mon, 3 Jun 2019 13:30:27 +0000 (07:30 -0600)
commit1b62781be08b73b2572be08ec3ac97068ba46b6f
treea3bc287ce5e77a60e628b07f40ccccec43dde7f5
parent9969c77bc29675a14cc765e782fa4bd677791ecb
res_fax: fix segfault on inactive "reserved" fax session

The change #10017 "Handle fax gateway being started more than once"
introdiced a bug which leads to segfault in res_fax_spandsp.

The res_fax_spandsp module does not support reserving sessions, so
fax_session_reserve returns a fax session with state AST_FAX_STATE_INACTIVE.

The fax_gateway_start does not create a real fax session if the fax session
is already present and the state is not AST_FAX_STATE_RESERVED.
But the "reserved" session created for res_fax_spandsp has state
AST_FAX_STATE_INACTIVE, so fax_gateway_start not starting.

Then when fax_gateway_framehook is called and gateway T.38 state is
NEGOTIATED the call of gateway->s->tech->write(gateway->s, f) leads to
segfault, because session tech_pvt is not set, i.e. the tech session
was not initialized/started.

This patch adds check also on AST_FAX_STATE_INACTIVE to the "reserved"
session created for res_fax_spandsp will start.

This patch also adds extra check and log ERROR if tech_pvt is not set
before call tech->write.

ASTERISK-27981 #close

Change-Id: Ife3e65e5f18c902db2ff0538fccf7d28f88fa803
res/res_fax.c