Commit Graph

53 Commits

Author SHA1 Message Date
Denis Grigorev
7a35c12a6c gobex: Fix segfault caused by interrupted transfer
When a obex transfer is interrupted by a peer in the middle, the response
G_OBEX_RSP_FORBIDDEN comes and the transfer is freed in transfer_complete.
However gobex is still ref'ed and gobex->io continues to be writable,
so write_data() and then g_obex_abort() are called. When the abort response
comes, struct obc_transfer is already freed, which leads to the crash.

Backtrace :
__GI___pthread_mutex_lock (mutex=0x65732f74) at pthread_mutex_lock.c:67
0xecc6eeda in dbus_connection_get_object_path_data () from libdbus-1.so.3
0x000457d4 in g_dbus_emit_property_changed_full () at gdbus/object.c:1794
0x00045868 in g_dbus_emit_property_changed () at gdbus/object.c:1832
0x000367f0 in transfer_set_status () at obexd/client/transfer.c:211
0x0003681e in transfer_set_status () at obexd/client/transfer.c:206
xfer_complete () at obexd/client/transfer.c:672
0x00022df6 in transfer_complete () at gobex/gobex-transfer.c:103
0x00022f44 in transfer_abort_response () at gobex/gobex-transfer.c:124
0x00020a0e in handle_response () at gobex/gobex.c:1128
0x00020dde in incoming_data () at gobex/gobex.c:1373

This commit introduces g_obex_drop_tx_queue(), which will be called if
a transfer error detected. After the tx queue is dropped, obex shuts
down gracefully.
2020-07-01 10:49:49 -07:00
Miao-chen Chou
4832ed0339 gobex: Fix a compilation error for the compatibility with LLVM
The C Standard, subclause 7.16.1.4, paragraph 4 [ISO/IEC 9899:2011], states:
The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with the register
storage class, with a function or array type, or with a type that is
not compatible with the type that results after application of the
default argument promotions, the behavior is undefined.
2016-12-07 16:03:58 +02:00
Johan Hedberg
66a85a3191 gobex: Minor coding style (whitespace) fix 2015-07-08 12:38:01 +03:00
Marcel Holtmann
7bd86b5b9e gobex: Fix includes for gobex.h header 2015-03-01 00:27:37 -08:00
Luiz Augusto von Dentz
31d69f8ecf gobex: Abort if there is no request to cancel
If there is no request to cancel send an abort since otherwise the remote
may hang waiting.
2014-08-29 10:32:27 +03:00
Luiz Augusto von Dentz
3ff1f6b5e8 gobex: Add g_obex_abort 2014-08-29 10:32:26 +03:00
Andrei Emeltchenko
cfdb4b82de gobex: Fix use after free
Refactor function transfer_get_req_first() to avoid use after free.
2014-08-11 16:27:56 +03:00
Andrei Emeltchenko
4830f41e03 gobex: Fix use after free 2014-08-11 16:26:37 +03:00
Andrei Emeltchenko
6df15b5415 gobex: Fix use after free
transfer_complete() frees transfer pointer.
2014-08-05 17:09:14 +03:00
Luiz Augusto von Dentz
0246b2d6bd gobex/transfer: Keep request id for GET when SRM is active
In case a GET operation is in progress with SRM the same request id is
valid for the whole transfer otherwise it is not possible to cancel the
transfer after the first response.
2014-03-21 16:13:44 +02:00
Luiz Augusto von Dentz
8a0fb5f525 gobex: Handle suspending/resuming for GET when SRM is active
This adds support for suspending/resuming GET requests GET when SRM is
active, in this case suspending the TX queue wont stop the remote
to continue sending packets, to do that SRMP header should be set to wait
so the remote should wait.
2014-02-20 13:43:08 +02:00
Luiz Augusto von Dentz
c9f3b81d07 gobex: Fix crash on g_obex_pending_req_abort
It is not safe to call g_obex_pending_req_abort directly as pending_req
can be NULL:
Invalid read of size 4
   at 0x41231E: g_obex_pending_req_abort (gobex.c:693)
   by 0x416A8A: g_obex_cancel_transfer (gobex-transfer.c:647)
   by 0x42DEF2: obc_transfer_cancel (transfer.c:180)
   by 0x43D833: process_message.isra.5 (object.c:259)
   by 0x3B0701CE85: ??? (in /usr/lib64/libdbus-1.so.3.7.4)
   by 0x3B0700FA30: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.4)
   by 0x43A5B7: message_dispatch (mainloop.c:76)
   by 0x3B03C48962: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C47E05: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C48157: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C48559: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x40D53C: main (main.c:319)
 Address 0x30 is not stack'd, malloc'd or (recently) free'd
2013-09-29 17:01:07 +03:00
Luiz Augusto von Dentz
0c6df3bb9b gobex: Add proper message to transfer errors
This improve the error message when a transfer fails by using
g_obex_strerror to decode the response code to a human readable string.
2013-08-12 11:13:51 +03:00
Johan Hedberg
30e2aaa3f8 gobex: Fix GPL version reference
These files (like everything else in the tree) should be GPL 2 or later
instead of GPL 2 only.
2013-02-15 16:25:29 +02:00
Johan Hedberg
b8779d2202 Revert "Ensure config.h is included by using CPPFLAGS"
This reverts commit 8a03376544.

The patch needs to be split up and the gdbus/ changes were bogus
compared to the original commit message.

Conflicts:
	Makefile.am
	Makefile.obexd
	profiles/cyclingspeed/cyclingspeed.c
	profiles/heartrate/heartrate.c
	src/error.c
2012-12-07 12:46:04 +02:00
Lucas De Marchi
8a03376544 Ensure config.h is included by using CPPFLAGS
Instead of trying to include config.h in each file over the tree and
possibly forgetting to include it, give a "-include config.h" argument
to the compiler so it's guaranteed that a) it will be included for all
source files and b) it will be the first header included.

gdbus/ directory is left out, since it would break other projects using
it.
2012-12-05 17:18:07 +02:00
Jaganath Kanakkassery
9095deb825 gobex: Add callback and userdata parameter to g_obex_cancel_transfer()
If callback is provided in g_obex_cancel_transfer() current complete
callback will be replaced by the new one and user will be informed
when abort completes.
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
faac92a4cb gobex: Translate posix error code to proper OBEX response opcode
This patch create a map between posix errors code and OBEX response
opcode and use it to generate a proper response in case a transfer
failed instead of always responding with internal error.
2012-12-04 22:22:05 +01:00
Luiz Augusto von Dentz
6e7d00ceec gobex: handle Single Response Mode (SRM) headers
Single Response Mode (SRM) is a 1-byte quantity containing a value to
enable or disable SRM, as well as to indicate support for SRM.
2012-12-04 22:22:05 +01:00
Luiz Augusto von Dentz
c11d66be4c gobex: introduce g_obex_get_rsp_pkt
g_obex_get_rsp_pkt takes a response packet which sometimes is more
convenient for adding headers.
2012-12-04 22:22:05 +01:00
Luiz Augusto von Dentz
ab6b0ae829 gobex: reduce duplicated code in g_obex_put_req
g_obex_put_req is quite similar to g_obex_put_req_pkt so now it just
call it to avoid duplicating this code.
2012-12-04 22:22:04 +01:00
Mikel Astiz
7dbc36186e gobex: fix transfer search in transfer_complete
The previous approach searched the transfer pointer itself, assuming
that the transfers has not been modified if the pointer is in the list.
However the callback could have removed the transfer and registered
another one, which can eventually point to the same memory location.

This is solved by looking for the transfer id instead of the pointer.
2012-12-04 22:22:04 +01:00
Luiz Augusto von Dentz
1c0b69678f gobex: fix removing wrong id on transfer_free
If statement checks for get_id handle but was removing req_id.
2012-12-04 22:22:04 +01:00
Luiz Augusto von Dentz
48bbe41993 gobex: log transfers using G_OBEX_DEBUG_TRANSFER 2012-12-04 22:22:03 +01:00
Luiz Augusto von Dentz
fffdbad4a8 gobex: log errors using G_OBEX_DEBUG_ERROR 2012-12-04 22:22:03 +01:00
Luiz Augusto von Dentz
e058d7a519 gobex: fix includes of config.h 2012-12-04 22:22:03 +01:00
Johan Hedberg
81dd14a05e gobex: Use larger timeout first packet in transfers
Frequently upon receiving the first packet servers will perform some
sort of user interaction to authorize the incoming request. It's
therefore wise to use a larger timeout for this first packet on the
client side.
2012-12-04 22:22:02 +01:00
Johan Hedberg
5c50f04098 gobex: Protect against transfer_complete callback removing the transfer 2012-12-04 22:22:02 +01:00
Johan Hedberg
4549f997e8 gobex: Add client transfer functions taking a pre-created GObexPacket 2012-12-04 22:22:02 +01:00
Luiz Augusto von Dentz
c96d0645b3 gobex: fix setting final bit on PUT requests
Final bit should not be set when creating new request packets for PUT
since it may be not be the end of the body.
2012-12-04 22:22:02 +01:00
Johan Hedberg
6814998db7 gobex: Remove reduntant empty line 2012-12-04 22:22:02 +01:00
Johan Hedberg
0528bfc1a0 gobex: Add support for returning -EAGAIN from producer callback 2012-12-04 22:22:02 +01:00
Johan Hedberg
f0598095d1 gobex: Premit raw OBEX error codes within G_OBEX_ERROR GError domain 2012-12-04 22:22:02 +01:00
Johan Hedberg
c38b06abda gobex: Refactor get response parsing in transfer code 2012-12-04 22:22:02 +01:00
Johan Hedberg
234c29546d gobex: Fix put request handling with final bit value 2012-12-04 22:22:01 +01:00
Johan Hedberg
ddb69649e8 gobex: Merge gobex-transfer.h into gobex.h 2012-12-04 22:22:01 +01:00
Johan Hedberg
57e1082eb0 gobex: Use guint instead of gint for request callback id 2012-12-04 22:22:01 +01:00
Johan Hedberg
815218c7ef gobex: Make transfer functions take va-args header lists 2012-12-04 22:22:01 +01:00
Johan Hedberg
58cd14d209 gobex: Remove _ID_ from header type definitions 2012-12-04 22:22:01 +01:00
Johan Hedberg
cdcde59687 gobex: Add va-args based packet creation support 2012-12-04 22:22:01 +01:00
Johan Hedberg
f5d10bf7cb gobex: Remove unneeded data_policy from g_obex_header_new_bytes 2012-12-04 22:22:01 +01:00
Johan Hedberg
25faf4fc79 gobex: Allow calling g_obex_get_rsp later with custom headers 2012-12-04 22:22:01 +01:00
Johan Hedberg
60263d9a33 gobex: Add g_obex_cancel_transfer 2012-12-04 22:22:00 +01:00
Johan Hedberg
5eb7afa856 gobex: Fix g_obex_get_rsp end of transfer handling 2012-12-04 22:22:00 +01:00
Johan Hedberg
98703e92d1 gobex: Add g_obex_get_rsp 2012-12-04 22:22:00 +01:00
Johan Hedberg
6abdccbf94 gobex: Add g_obex_get_req 2012-12-04 22:22:00 +01:00
Johan Hedberg
a2ced03a85 gobex: Don't call consumer callback if there is no data 2012-12-04 22:22:00 +01:00
Johan Hedberg
d070d17059 gobex: Add basic server-side put transfer support 2012-12-04 22:21:59 +01:00
Johan Hedberg
10dfec83a1 gobex: Rename g_obex_put to g_obex_put_req 2012-12-04 22:21:59 +01:00
Johan Hedberg
2af993b895 gobex: Add type and name headers to the g_obex_put request 2012-12-04 22:21:59 +01:00