dexter has uploaded this change for review.

View Change

sndcp: use signed integer to store negative return code

The functiion gprs_sndcp_sne_handle_sn_xid_req calls
gprs_sndcp_sne_gen_sndcp_xid, which eventually calls
gprs_sndcp_compile_xid. The resulting return code of this
chain is stored in an unsigned integer variable.

This was no problem since gprs_sndcp_compile_xid couldn't
return a negative value until we have fixed the error handling
recently. Before the fixes, gprs_sndcp_compile_xid would have
crashed the whole process through OSMO_ASSERT checks. Because
of that, negative returns simply weren't possible, even though
the return type of the function is signed integer.

Let's now use a signed integer variable (rc) to catch the
return code and do the negative check based on rc. When the
return code is positive, we store the value in sne->l3xid_req_len,
otherwise make sure that sne->l3xid_req_len is set to 0 for
good measure.

Change-Id: I25cc44207bdc0ad36e206426c11ed696a17f6080
Related: OS#7095
Fixes: CID#565319
---
M src/sndcp/sndcp.c
1 file changed, 4 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmo-gprs refs/changes/95/43995/1
diff --git a/src/sndcp/sndcp.c b/src/sndcp/sndcp.c
index 88c4979..cdb33fa 100644
--- a/src/sndcp/sndcp.c
+++ b/src/sndcp/sndcp.c
@@ -800,14 +800,16 @@
sne->snme->comp.data = gprs_sndcp_comp_alloc(sne->snme);

/* Generate compression parameter bytestream */
- sne->l3xid_req_len = gprs_sndcp_sne_gen_sndcp_xid(sne, l3params, sizeof(l3params), sndcp_prim);
- if (sne->l3xid_req_len > 0) {
+ rc = gprs_sndcp_sne_gen_sndcp_xid(sne, l3params, sizeof(l3params), sndcp_prim);
+ if (rc > 0) {
+ sne->l3xid_req_len = rc;
talloc_free(sne->l3xid_req);
sne->l3xid_req = talloc_size(sne, sne->l3xid_req_len);
memcpy(sne->l3xid_req, l3params, sne->l3xid_req_len);
} else {
talloc_free(sne->l3xid_req);
sne->l3xid_req = NULL;
+ sne->l3xid_req_len = 0;
}
sne->xid_req_in_transit_orig_sn_xid_req = true;


To view, visit change 43995. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-gprs
Gerrit-Branch: master
Gerrit-Change-Id: I25cc44207bdc0ad36e206426c11ed696a17f6080
Gerrit-Change-Number: 43995
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>