[sr-dev] git:5.2:879fb530: pdb: use memcpy() for PDB_BUFTOSHORT macro

Henning Westerholt hw at skalatan.de
Fri Oct 2 16:21:34 CEST 2020


Module: kamailio
Branch: 5.2
Commit: 879fb5300a1d90a6d958f8a263d243a9cd7fa9fa
URL: https://github.com/kamailio/kamailio/commit/879fb5300a1d90a6d958f8a263d243a9cd7fa9fa

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Henning Westerholt <hw at skalatan.de>
Date: 2020-10-02T14:21:12Z

pdb: use memcpy() for PDB_BUFTOSHORT macro

- related to GH #2345

(cherry picked from commit be57be33d0e48d412ddab9801ee4d6d906329d70)

---

Modified: src/modules/pdb/pdb.c

---

Diff:  https://github.com/kamailio/kamailio/commit/879fb5300a1d90a6d958f8a263d243a9cd7fa9fa.diff
Patch: https://github.com/kamailio/kamailio/commit/879fb5300a1d90a6d958f8a263d243a9cd7fa9fa.patch

---

diff --git a/src/modules/pdb/pdb.c b/src/modules/pdb/pdb.c
index 1ab15af2e7..5fb1204e52 100644
--- a/src/modules/pdb/pdb.c
+++ b/src/modules/pdb/pdb.c
@@ -190,7 +190,7 @@ static int pdb_msg_format_send(struct pdb_msg *msg,
 
 
 /* two chars to short-int without caring of memory alignment in char buffer */
-#define PDB_BUFTOSHORT(_b, _n) (((short int)_b[_n]) << 8) | (0x00ff & _b[_n+1])
+#define PDB_BUFTOSHORT(_sv, _b, _n) memcpy(&(_sv), (char*)(_b) + (_n), sizeof(short int))
 
 /*!
  * \return 1 if query for the number succeded and the avp with the corresponding carrier id was set,
@@ -347,7 +347,7 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct
                                 case PDB_CODE_OK:
                                     msg.bdy.payload[sizeof(struct pdb_bdy) - 1] = '\0';
                                     if (strcmp(msg.bdy.payload, number.s) == 0) {
-                                        _id = PDB_BUFTOSHORT(msg.bdy.payload, reqlen); /* make gcc happy */
+                                        PDB_BUFTOSHORT(_id, msg.bdy.payload, reqlen); /* make gcc happy */
                                         carrierid=ntohs(_id); /* convert to host byte order */
                                         goto found;
                                     }
@@ -370,7 +370,7 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct
                         default:
                             buf[sizeof(struct pdb_msg) - 1] = '\0';
                             if (strncmp(buf, number.s, number.len) == 0) {
-                                _id = PDB_BUFTOSHORT(buf, reqlen); /* make gcc happy */
+                                PDB_BUFTOSHORT(_id, buf, reqlen); /* make gcc happy */
                                 carrierid=ntohs(_id); /* convert to host byte order */
                                 goto found;
                             }




More information about the sr-dev mailing list