inet_ntoa was called twice in a row and as a result both primay and
secondary DNS were pointing to same static buffer containing last
value (secondary DNS).

As a result, ofono always advertised the secondary DNS twice through
DBus ConnectionContext.GetProperties 'DomainNameServers'.

Related: https://osmocom.org/issues/3031
---
 drivers/qmimodem/gprs-context.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/qmimodem/gprs-context.c b/drivers/qmimodem/gprs-context.c
index dcdf8ae1..f1fd1f12 100644
--- a/drivers/qmimodem/gprs-context.c
+++ b/drivers/qmimodem/gprs-context.c
@@ -88,6 +88,7 @@ static void get_settings_cb(struct qmi_result *result, void 
*user_data)
        char* straddr;
        char* apn;
        const char *dns[3] = { NULL, NULL, NULL };
+       char dns_buf[2][INET_ADDRSTRLEN];
 
        DBG("");
 
@@ -131,14 +132,14 @@ static void get_settings_cb(struct qmi_result *result, 
void *user_data)
        if (qmi_result_get_uint32(result,
                                QMI_WDS_RESULT_PRIMARY_DNS, &ip_addr)) {
                addr.s_addr = htonl(ip_addr);
-               dns[0] = inet_ntoa(addr);
+               dns[0] = inet_ntop(AF_INET, &addr, dns_buf[0], 
sizeof(dns_buf[0]));
                DBG("Primary DNS: %s", dns[0]);
        }
 
        if (qmi_result_get_uint32(result,
                                QMI_WDS_RESULT_SECONDARY_DNS, &ip_addr)) {
                addr.s_addr = htonl(ip_addr);
-               dns[1] = inet_ntoa(addr);
+               dns[1] = inet_ntop(AF_INET, &addr, dns_buf[1], 
sizeof(dns_buf[1]));
                DBG("Secondary DNS: %s", dns[1]);
        }
 
-- 
2.19.2

_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to