From patchwork Thu Feb 29 23:56:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13577763 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C84FA13E7D4 for ; Thu, 29 Feb 2024 23:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709251024; cv=none; b=V2GBLe/0Ok/BZoRZdxTQABCX13cEyYoYX7uT1JaVSfhnPlTZ1gnwcxGEtcPH9wrzmAe2j94Ens7g2qMfTQ/ldz1Ap/k9cuD0mw+kzcj7GCykynlse2eEQR0213AgXIlw5gTpRRkNBAkKXSraYvNJRpHmQwMFKLABACsFBLrqzJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709251024; c=relaxed/simple; bh=qMrPX3B0ea9JH7iXks5jZGBltkUg328nkgR3BjUGZlM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DOL4RwKLxf3qD6RA9ZutQ9z1M/1gpz8mwp6MAC+8F/3P9UBSgUZUI5C+D0CZIPGI1NcTzu9zJ/m6DM9pRG8pNdT2E0Tkh0m5bazJg+BgGtg01uWAx5mG4ZaCoItKmGaJGgX5fBicZN3a3qFR3rd3hpSrzPLeUvGdWLfE1/4WY1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S/fh6Nc/; arc=none smtp.client-ip=209.85.210.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S/fh6Nc/" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6e49a5b1bbfso750970a34.3 for ; Thu, 29 Feb 2024 15:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709251022; x=1709855822; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UsJ/vc7UBnX7r1irL3SxA5VOv/+YGwf/fxgBlUNaTFU=; b=S/fh6Nc/m66Hqc6slvwAxaOsdQ7tbjxBrxmrVs5/bOoIXEBRnuKC3bluCbaup3yTah nqq/PYvImOy+6dTTqYSdNNEUbw/+NY3uc/3tmB7Anhwc4E09J0/eO9vCpY3JUJIkdBZI iOo6GkQPrwA2eLPe+wXSP4pFngkuNqsHge8cTIicWAWtBmuQ9rE5qDd/IrrlQrFp9UKc 0x9lcCbhFhXxSg6oaeY6F48vQixUDO+810ii01RwFmnyRIsVd60C/bN2zEblnfr7uvxs /N0KcNah810eNQ47+rW+o+KAodB9Xju5gZ1rNK80g6niYY0Jo6KhWmmhgfM/1DvQbXDe TAEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709251022; x=1709855822; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UsJ/vc7UBnX7r1irL3SxA5VOv/+YGwf/fxgBlUNaTFU=; b=BuNNSf1Kc1NXktGEDNySQUIi92ACt6I6pVSAwoRpzy5hgIGEGp7pvC0NxgvHEceQes VuW56Zd1t89tMMDoLzbF89Qh61Dk2eReNEYmj8NosLvUaUx0ZKpyXgu2c8URzIktnGKS 29TV9biOv2tV8ASWOa1kJEKGjtWTWiShLBTPMrhrRuQ1ejii8FjdWoe5oiTCxaFBY9zO /AhSjN5DlnCysx3u+Qi3ocCxCA4bMc/+tV9B5SyLRM2fvH5tNZ1y+K0i7G3o0NmhLsqF j2Cwd3X5ScTaF2qiPo9Gqr7nsR2ix9DZ7BM8srihM4gn6xwAHS2GVEf7f2eE0qZjy91Q FjYw== X-Gm-Message-State: AOJu0YxS/9nQv5XA2MGn0PSRlnCRYG78hHe0yrFTNMEDaEiWVzh7es7M dU1iZ4aqma8wZnIRVIcC6jRoBq4IzEoCiZxly4rheu2+ulfFCYkkYFyaMFMz X-Google-Smtp-Source: AGHT+IFhr8+YWDnR9SlEhIt9VPqiM6ZQv97fg6m3G25096iPf69UPDTTNPz26s1iRjvwVhAbqf8dGw== X-Received: by 2002:a9d:7347:0:b0:6e4:b7ba:31ab with SMTP id l7-20020a9d7347000000b006e4b7ba31abmr336235otk.0.1709251021728; Thu, 29 Feb 2024 15:57:01 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id w3-20020a056830060300b006e4b3c42595sm473924oti.32.2024.02.29.15.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:57:01 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/2] smsutil: Use a safer strlcpy Date: Thu, 29 Feb 2024 17:56:41 -0600 Message-ID: <20240229235658.1703008-1-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 sms_address_from_string is meant as private API, to be used with string form addresses that have already been sanitized. However, to be safe, use a safe version of strcpy to avoid overflowing the buffer in case the input was not sanitized properly. While here, add a '__' prefix to the function name to help make it clearer that this API is private and should be used with more care. --- src/smsutil.c | 14 +++++++------- src/smsutil.h | 2 +- unit/test-sms.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/smsutil.c b/src/smsutil.c index 6fe2bcb4477f..5934da9055dd 100644 --- a/src/smsutil.c +++ b/src/smsutil.c @@ -1887,15 +1887,15 @@ time_t sms_scts_to_time(const struct sms_scts *scts, struct tm *remote) return ret; } -void sms_address_from_string(struct sms_address *addr, const char *str) +void __sms_address_from_string(struct sms_address *addr, const char *str) { addr->numbering_plan = SMS_NUMBERING_PLAN_ISDN; if (str[0] == '+') { addr->number_type = SMS_NUMBER_TYPE_INTERNATIONAL; - strcpy(addr->address, str + 1); + l_strlcpy(addr->address, str + 1, sizeof(addr->address)); } else { addr->number_type = SMS_NUMBER_TYPE_UNKNOWN; - strcpy(addr->address, str); + l_strlcpy(addr->address, str, sizeof(addr->address)); } } @@ -3084,7 +3084,7 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly, } } - sms_address_from_string(&addr, straddr); + __sms_address_from_string(&addr, straddr); if (pending == TRUE && node->deliverable == TRUE) { /* @@ -3177,7 +3177,7 @@ void status_report_assembly_expire(struct status_report_assembly *assembly, while (g_hash_table_iter_next(&iter_addr, (gpointer) &straddr, (gpointer) &id_table)) { - sms_address_from_string(&addr, straddr); + __sms_address_from_string(&addr, straddr); g_hash_table_iter_init(&iter_node, id_table); /* Go through different messages. */ @@ -3470,7 +3470,7 @@ GSList *sms_datagram_prepare(const char *to, template.submit.vp.relative = 0xA7; /* 24 Hours */ template.submit.dcs = 0x04; /* Class Unspecified, 8 Bit */ template.submit.udhi = TRUE; - sms_address_from_string(&template.submit.daddr, to); + __sms_address_from_string(&template.submit.daddr, to); offset = 1; @@ -3597,7 +3597,7 @@ GSList *sms_text_prepare_with_alphabet(const char *to, const char *utf8, template.submit.srr = use_delivery_reports; template.submit.mr = 0; template.submit.vp.relative = 0xA7; /* 24 Hours */ - sms_address_from_string(&template.submit.daddr, to); + __sms_address_from_string(&template.submit.daddr, to); /* There are two enums for the same thing */ dialect = (enum gsm_dialect)alphabet; diff --git a/src/smsutil.h b/src/smsutil.h index 5389757c309c..98e10e15de72 100644 --- a/src/smsutil.h +++ b/src/smsutil.h @@ -465,7 +465,7 @@ int sms_udl_in_bytes(guint8 ud_len, guint8 dcs); time_t sms_scts_to_time(const struct sms_scts *scts, struct tm *remote); const char *sms_address_to_string(const struct sms_address *addr); -void sms_address_from_string(struct sms_address *addr, const char *str); +void __sms_address_from_string(struct sms_address *addr, const char *str); const guint8 *sms_extract_common(const struct sms *sms, gboolean *out_udhi, guint8 *out_dcs, guint8 *out_udl, diff --git a/unit/test-sms.c b/unit/test-sms.c index 154bb33ed244..66755f34e603 100644 --- a/unit/test-sms.c +++ b/unit/test-sms.c @@ -1603,7 +1603,7 @@ static void test_sr_assembly(void) sr3.status_report.mr); } - sms_address_from_string(&addr, "+4915259911630"); + __sms_address_from_string(&addr, "+4915259911630"); sra = status_report_assembly_new(NULL); @@ -1626,7 +1626,7 @@ static void test_sr_assembly(void) * Send sms-message in the national address-format, * but receive in the international address-format. */ - sms_address_from_string(&addr, "9911630"); + __sms_address_from_string(&addr, "9911630"); status_report_assembly_add_fragment(sra, sha1, &addr, 4, time(NULL), 2); status_report_assembly_add_fragment(sra, sha1, &addr, 5, time(NULL), 2); @@ -1641,7 +1641,7 @@ static void test_sr_assembly(void) * Send sms-message in the international address-format, * but receive in the national address-format. */ - sms_address_from_string(&addr, "+358123456789"); + __sms_address_from_string(&addr, "+358123456789"); status_report_assembly_add_fragment(sra, sha1, &addr, 6, time(NULL), 1); g_assert(status_report_assembly_report(sra, &sr3, id, &delivered)); From patchwork Thu Feb 29 23:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13577764 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B964344374 for ; Thu, 29 Feb 2024 23:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709251025; cv=none; b=d1DZruavshBK9FK/1dJpEEG4U5izj5oHbl2anU6aXu/G9eZZ4QQnxNqrb2j1kk5fboqLkEY2Bw001wX43bpBiIPXwIKSpBjQY1RN9habLQKMOWL5FSpCkzBFQD7XtM9orhg80/OyBrWGSKC0TxgrRv/7QZi0oYlbut6RZwX3y6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709251025; c=relaxed/simple; bh=Cs5i13xlEPgjfcS6MG9zmuhLJNqoGzoAt0gnvYM2dpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i5X5hcEDzi4LsY+5AidTJ4uqMtT110zhsF+PLvASyYDOe2hnQJrP8pKKmYdy7mRb0O+t0GyM03GroaGtr8cIHM+TSbda+q1ZI6QVdOOOFao+VksiRYllIh/9F+1uAZdGO+w7SvvYzuedRYlJgRCLi/EmYrlb2dzq3KzQ2YFJnA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JtRnXdcw; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JtRnXdcw" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6e4c1d243b4so534996a34.2 for ; Thu, 29 Feb 2024 15:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709251023; x=1709855823; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lRqoGTPmQJ86eYXoX36fi9ACS5FMscO/yGW5TsJMK8o=; b=JtRnXdcw0v480Ur05W85JZ4ylxDZhVLUHOPouXHgnP3w3bre7jvpWSOgR77IAu6WD8 dz0GmRBVak6/d2lCARyNDsKZldAWvejTp1oeXGjH7thWC1pr/eJ8NODqN4+OPQQlkwGZ ftbT5Y3z3XEJIAYOm3YOQoiB5qPWeGzcUiHWpOmPJFO2Nj0MzocyQHr8QggejuTzajUV 7AzuI+PY3JrOMiJ6JMNE1EE9lnO05igFiHFuzKaVnDy7VqxrOBLhw2eyWgy7AOytfDuU QVc3/ppK0WV0Cfk+9D7sEm383PNYk2uoTCkbOPCzu5xwi8eoBjts7tfqHkn2gcjo8a4K ISZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709251023; x=1709855823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lRqoGTPmQJ86eYXoX36fi9ACS5FMscO/yGW5TsJMK8o=; b=KX3rmbAeeKlSnrRdmuIrYA1g7C5tyL1VBaUayyJk/+ogvfaMsGqOypattGj+6OhntD K7fcNHx0nIaRy6xH98lf1udcR3CXoy165YLdsR7JrnbbpmzjoedjhO08mqY7LDxz7k1j NFlmjBYPAYtFCGm0D9rIXXaiQjzfVRXnjMIZPYdvF2AP3MIDCfHU2NUoJw53m5vkiSmJ 25E0QT3c00+SeLjtbcH83SZCUjLfoQplotDOgUmQ1nuXUTytSUn9yPbOLPbXtZzk2wYC bYatdGR1RveiSlgf/TMr3z8pDAT9qoWtLWNnS6B1e18xrYLHckeoX3Ayk/5CijoWOeD6 nDEg== X-Gm-Message-State: AOJu0YwF1i3aY4G9lr48I/7VDBDpDWxgezPxpUo0RzhkCAY9kqs4vsj3 WS3M/8lIZIXHGjryKS0V670Rf8SyZS00+RHPpmuOx84ghMGHzYVxJJ2j6qZ9 X-Google-Smtp-Source: AGHT+IHTo3AvDdGhLImvvA/pasEUG1wSyaYHO+JiTpDvk2CvCUKL6o3CLqGNu8SFg8+lZpHbQ3Y9Qg== X-Received: by 2002:a9d:62cf:0:b0:6e4:ac86:634a with SMTP id z15-20020a9d62cf000000b006e4ac86634amr175788otk.33.1709251022623; Thu, 29 Feb 2024 15:57:02 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id w3-20020a056830060300b006e4b3c42595sm473924oti.32.2024.02.29.15.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:57:02 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/2] voicecall: Refactor string_to_phone_number Date: Thu, 29 Feb 2024 17:56:42 -0600 Message-ID: <20240229235658.1703008-2-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229235658.1703008-1-denkenz@gmail.com> References: <20240229235658.1703008-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 string_to_phone_number is used to convert a sanitized phone number string to struct ofono_phone_number. An unsafe strcpy is used for the conversion. Change string_to_phone_number in two ways: - Add a '__' prefix to make it clear that this API is private and care must be taken when using it. In this case, by sanitizing the input first - Use a safer strcpy version, namely l_strlcpy While here, add a sanitizing version of string_to_phone_number that can be used to sanitize and convert the input string in one operation. Also take the opportunity to convert some of the functions involved from GLib gboolean type to stdbool. --- plugins/smart-messaging.c | 4 ++-- src/call-forwarding.c | 4 ++-- src/common.c | 41 ++++++++++++++++++++++++++------------- src/common.h | 10 ++++++---- src/message-waiting.c | 4 ++-- src/sim.c | 2 +- src/sms.c | 4 +--- src/voicecall.c | 10 +++------- 8 files changed, 44 insertions(+), 35 deletions(-) diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c index 0c9700d23b48..e7dffbb0508c 100644 --- a/plugins/smart-messaging.c +++ b/plugins/smart-messaging.c @@ -201,7 +201,7 @@ static DBusMessage *smart_messaging_send_vcard(DBusConnection *conn, &bytes, &len, DBUS_TYPE_INVALID)) return __ofono_error_invalid_args(msg); - if (valid_phone_number_format(to) == FALSE) + if (!valid_phone_number_format(to)) return __ofono_error_invalid_format(msg); ref = __ofono_sms_get_next_ref(sm->sms); @@ -243,7 +243,7 @@ static DBusMessage *smart_messaging_send_vcal(DBusConnection *conn, &bytes, &len, DBUS_TYPE_INVALID)) return __ofono_error_invalid_args(msg); - if (valid_phone_number_format(to) == FALSE) + if (!valid_phone_number_format(to)) return __ofono_error_invalid_format(msg); ref = __ofono_sms_get_next_ref(sm->sms); diff --git a/src/call-forwarding.c b/src/call-forwarding.c index d5bf70691b9e..69b587044332 100644 --- a/src/call-forwarding.c +++ b/src/call-forwarding.c @@ -794,7 +794,7 @@ static DBusMessage *cf_set_property(DBusConnection *conn, DBusMessage *msg, return __ofono_error_not_available(msg); if (number[0] != '\0') - string_to_phone_number(number, &ph); + __string_to_phone_number(number, &ph); timeout = cf_cond_find_timeout(cf->cf_conditions[type], cls); @@ -1206,7 +1206,7 @@ static gboolean cf_ss_control(int type, const char *sc, switch (cf->ss_req->ss_type) { case SS_CONTROL_TYPE_REGISTRATION: - string_to_phone_number(sia, &ph); + __string_to_phone_number(sia, &ph); cf->driver->registration(cf, cf_type, cls, &ph, timeout, cf_ss_control_callback, cf); break; diff --git a/src/common.c b/src/common.c index aff356da3330..57b04424b9f2 100644 --- a/src/common.c +++ b/src/common.c @@ -236,23 +236,27 @@ struct error_entry ceer_errors[] = { { 127, "Interworking, unspecified" }, }; -gboolean valid_number_format(const char *number, int length) +bool valid_number_format(const char *number, size_t length) { - int len = strlen(number); - int begin = 0; - int i; + size_t len; + size_t begin = 0; + size_t i; + + if (!number) + return false; + len = strlen(number); if (!len) - return FALSE; + return false; if (number[0] == '+') begin = 1; if (begin == len) - return FALSE; + return false; if ((len - begin) > length) - return FALSE; + return false; for (i = begin; i < len; i++) { if (number[i] >= '0' && number[i] <= '9') @@ -261,10 +265,10 @@ gboolean valid_number_format(const char *number, int length) if (number[i] == '*' || number[i] == '#') continue; - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -273,12 +277,12 @@ gboolean valid_number_format(const char *number, int length) * Destination address, or EFADN (Abbreviated dialling numbers), * are up 20 digits. */ -gboolean valid_phone_number_format(const char *number) +bool valid_phone_number_format(const char *number) { return valid_number_format(number, 20); } -gboolean valid_long_phone_number_format(const char *number) +bool valid_long_phone_number_format(const char *number) { return valid_number_format(number, OFONO_MAX_PHONE_NUMBER_LENGTH); } @@ -415,17 +419,26 @@ const char *phone_number_to_string(const struct ofono_phone_number *ph) return buffer; } -void string_to_phone_number(const char *str, struct ofono_phone_number *ph) +void __string_to_phone_number(const char *str, struct ofono_phone_number *ph) { if (str[0] == '+') { - strcpy(ph->number, str+1); + l_strlcpy(ph->number, str + 1, sizeof(ph->number)); ph->type = 145; /* International */ } else { - strcpy(ph->number, str); + l_strlcpy(ph->number, str, sizeof(ph->number)); ph->type = 129; /* Local */ } } +int string_to_phone_number(const char *str, struct ofono_phone_number *ph) +{ + if (!valid_phone_number_format(str)) + return -EINVAL; + + __string_to_phone_number(str, ph); + return 0; +} + gboolean valid_ussd_string(const char *str, gboolean call_in_progress) { int len = strlen(str); diff --git a/src/common.h b/src/common.h index bfbf2cff0437..cede20d1de32 100644 --- a/src/common.h +++ b/src/common.h @@ -159,11 +159,13 @@ enum context_status { const char *telephony_error_to_str(const struct ofono_error *error); -gboolean valid_number_format(const char *number, int length); -gboolean valid_phone_number_format(const char *number); -gboolean valid_long_phone_number_format(const char *number); +bool valid_number_format(const char *number, size_t length); +bool valid_phone_number_format(const char *number); +bool valid_long_phone_number_format(const char *number); const char *phone_number_to_string(const struct ofono_phone_number *ph); -void string_to_phone_number(const char *str, struct ofono_phone_number *ph); + +void __string_to_phone_number(const char *str, struct ofono_phone_number *ph); +int string_to_phone_number(const char *str, struct ofono_phone_number *ph); int mmi_service_code_to_bearer_class(int code); diff --git a/src/message-waiting.c b/src/message-waiting.c index 6115d495f5dd..7a3b2d8932d2 100644 --- a/src/message-waiting.c +++ b/src/message-waiting.c @@ -199,7 +199,7 @@ static DBusMessage *set_cphs_mbdn(struct ofono_message_waiting *mw, req->mw = mw; req->mailbox = mailbox; - string_to_phone_number(number, &req->number); + __string_to_phone_number(number, &req->number); req->cphs = TRUE; sim_adn_build(efmbdn, req->mw->ef_cphs_mbdn_length, @@ -298,7 +298,7 @@ static DBusMessage *set_mbdn(struct ofono_message_waiting *mw, int mailbox, req->mw = mw; req->mailbox = mailbox; - string_to_phone_number(number, &req->number); + __string_to_phone_number(number, &req->number); req->cphs = FALSE; sim_adn_build(efmbdn, req->mw->efmbdn_length, &req->number, NULL); diff --git a/src/sim.c b/src/sim.c index 137441d2a127..8a97e87612d9 100644 --- a/src/sim.c +++ b/src/sim.c @@ -748,7 +748,7 @@ static DBusMessage *sim_set_property(DBusConnection *conn, DBusMessage *msg, goto error; own = g_new0(struct ofono_phone_number, 1); - string_to_phone_number(value, own); + __string_to_phone_number(value, own); own_numbers = g_slist_prepend(own_numbers, own); diff --git a/src/sms.c b/src/sms.c index 2fc91f9e2162..2b440c59fec0 100644 --- a/src/sms.c +++ b/src/sms.c @@ -552,15 +552,13 @@ static DBusMessage *sms_set_property(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(&var, &value); - if (strlen(value) == 0 || !valid_phone_number_format(value)) + if (string_to_phone_number(value, &sca) < 0) return __ofono_error_invalid_format(msg); if (sms->driver->sca_set == NULL || sms->driver->sca_query == NULL) return __ofono_error_not_implemented(msg); - string_to_phone_number(value, &sca); - sms->pending = dbus_message_ref(msg); sms->driver->sca_set(sms, &sca, sca_set_callback, sms); diff --git a/src/voicecall.c b/src/voicecall.c index 1bf96ee179b4..d9f3dd82f0e6 100644 --- a/src/voicecall.c +++ b/src/voicecall.c @@ -499,7 +499,6 @@ static DBusMessage *voicecall_deflect(DBusConnection *conn, struct voicecall *v = data; struct ofono_voicecall *vc = v->vc; struct ofono_call *call = v->call; - struct ofono_phone_number ph; const char *number; @@ -517,13 +516,10 @@ static DBusMessage *voicecall_deflect(DBusConnection *conn, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!valid_phone_number_format(number)) + if (string_to_phone_number(number, &ph) < 0) return __ofono_error_invalid_format(msg); vc->pending = dbus_message_ref(msg); - - string_to_phone_number(number, &ph); - vc->driver->deflect(vc, &ph, generic_callback, vc); return NULL; @@ -1368,7 +1364,7 @@ static struct voicecall *synthesize_outgoing_call(struct ofono_voicecall *vc, call->id = id; if (number) - string_to_phone_number(number, &call->phone_number); + __string_to_phone_number(number, &call->phone_number); call->direction = CALL_DIRECTION_MOBILE_ORIGINATED; call->status = CALL_STATUS_DIALING; @@ -1511,7 +1507,7 @@ static int voicecall_dial(struct ofono_voicecall *vc, const char *number, if (is_emergency_number(vc, number) == TRUE) __ofono_modem_inc_emergency_mode(modem); - string_to_phone_number(number, &ph); + __string_to_phone_number(number, &ph); if (vc->settings) { g_key_file_set_string(vc->settings, SETTINGS_GROUP,