summaryrefslogtreecommitdiff
path: root/src/libgsmd
diff options
context:
space:
mode:
authortick <tick@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-12-01 01:57:09 +0000
committertick <tick@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-12-01 01:57:09 +0000
commit9fd5a57b64a19cf9850fcd3a333fb926f2bf1a44 (patch)
tree28fdf4d5f94e89bd70308d665efa38a495379154 /src/libgsmd
parentd88e15979081740b86f48a78c81df56f5122a2c4 (diff)
gsmd: Severe clean-up (Andrzej Zaborowski)
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3546 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/libgsmd')
-rw-r--r--src/libgsmd/libgsmd.c2
-rw-r--r--src/libgsmd/libgsmd_event.c5
-rw-r--r--src/libgsmd/libgsmd_passthrough.c17
-rw-r--r--src/libgsmd/libgsmd_pin.c4
4 files changed, 15 insertions, 13 deletions
diff --git a/src/libgsmd/libgsmd.c b/src/libgsmd/libgsmd.c
index b5d163f..b9db59a 100644
--- a/src/libgsmd/libgsmd.c
+++ b/src/libgsmd/libgsmd.c
@@ -133,7 +133,7 @@ void lgsm_unregister_handler(struct lgsm_handle *lh, int type)
}
/* blocking read and processing of packets until packet matching 'id' is found */
-int lgsm_blocking_wait_packet(struct lgsm_handle *lh, u_int16_t id,
+int lgsm_blocking_wait_packet(struct lgsm_handle *lh, u_int16_t id,
struct gsmd_msg_hdr *gmh, int rlen)
{
int rc;
diff --git a/src/libgsmd/libgsmd_event.c b/src/libgsmd/libgsmd_event.c
index 777edd8..b01a8b2 100644
--- a/src/libgsmd/libgsmd_event.c
+++ b/src/libgsmd/libgsmd_event.c
@@ -52,9 +52,10 @@ void lgsm_evt_handler_unregister(struct lgsm_handle *lh, int evt_type)
}
-static int evt_demux_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
+static int evt_demux_msghandler(struct lgsm_handle *lh,
+ struct gsmd_msg_hdr *gmh)
{
- struct gsmd_evt_auxdata *aux = gmh->data;
+ struct gsmd_evt_auxdata *aux = (struct gsmd_evt_auxdata *) gmh->data;
if (gmh->len < sizeof(*aux))
return -EIO;
diff --git a/src/libgsmd/libgsmd_passthrough.c b/src/libgsmd/libgsmd_passthrough.c
index b6b32fc..1849688 100644
--- a/src/libgsmd/libgsmd_passthrough.c
+++ b/src/libgsmd/libgsmd_passthrough.c
@@ -59,7 +59,8 @@ int lgsm_passthrough_send(struct lgsm_handle *lh, const char *tx)
return gmh->id;
}
-int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned int *rx_len)
+int lgsm_passthrough(struct lgsm_handle *lh, const char *tx,
+ char *rx, unsigned int *rx_len)
{
struct gsmd_msg_hdr *rgmh = (struct gsmd_msg_hdr *)passthrough_rbuf;
char *rx_buf = (char *)rgmh + sizeof(*rgmh);
@@ -72,8 +73,7 @@ int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned
/* since we synchronously want to wait for a response, we need to
* _internally_ loop over incoming packets and call the callbacks for
* intermediate messages (if applicable) */
- rc = lgsm_blocking_wait_packet(lh, rc, passthrough_rbuf,
- sizeof(passthrough_rbuf));
+ rc = lgsm_blocking_wait_packet(lh, rc, rgmh, sizeof(passthrough_rbuf));
if (rc <= 0)
return rc;
@@ -82,10 +82,11 @@ int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned
if (rc < sizeof(*rgmh) + rgmh->len)
return -EINVAL;
-
- /* FIXME: make sure rx_buf is zero-terminated */
- strcpy(rx, rx_buf);
- *rx_len = rgmh->len;
- return rx_len;
+ rx[*--rx_len] = 0;
+ if (rgmh->len < *rx_len)
+ *rx_len = rgmh->len;
+ memcpy(rx, rx_buf, *rx_len);
+
+ return *rx_len;
}
diff --git a/src/libgsmd/libgsmd_pin.c b/src/libgsmd/libgsmd_pin.c
index f99084a..204f655 100644
--- a/src/libgsmd/libgsmd_pin.c
+++ b/src/libgsmd/libgsmd_pin.c
@@ -75,7 +75,7 @@ int lgsm_pin(struct lgsm_handle *lh, unsigned int type,
return -ENOMEM;
gm->gp.type = type;
- strcpy(gm->gp.pin, pin);
+ strncpy(gm->gp.pin, pin, sizeof(gm->gp.pin));
switch (type) {
case GSMD_PIN_SIM_PUK:
@@ -87,7 +87,7 @@ int lgsm_pin(struct lgsm_handle *lh, unsigned int type,
free(gm);
return -EINVAL;
}
- strcpy(gm->gp.newpin, newpin);
+ strncpy(gm->gp.newpin, newpin, sizeof(gm->gp.newpin));
break;
default:
break;
personal git repositories of Harald Welte. Your mileage may vary