Bug 1102023 - Should not decode IccId as extended BCD number. r=hsinyi

This commit is contained in:
Edgar Chen 2014-12-10 15:04:52 +08:00
parent 51edb9c86e
commit 713a473470
3 changed files with 86 additions and 25 deletions

View File

@ -7058,21 +7058,21 @@ GsmPDUHelperObject.prototype = {
},
/**
* Convert a semi-octet (number) to a GSM BCD char, or return empty string
* if invalid semiOctet and supressException is set to true.
* Convert a semi-octet (number) to a GSM BCD char, or return empty
* string if invalid semiOctet and suppressException is set to true.
*
* @param semiOctet
* Nibble to be converted to.
* @param [optional] supressException
* Supress exception if invalid semiOctet and supressException is set
* @param suppressException [optional]
* Suppress exception if invalid semiOctet and suppressException is set
* to true.
*
* @return GSM BCD char, or empty string.
*/
bcdChars: "0123456789*#,;",
semiOctetToBcdChar: function(semiOctet, supressException) {
if (semiOctet >= 14) {
if (supressException) {
bcdChars: "0123456789",
semiOctetToBcdChar: function(semiOctet, suppressException) {
if (semiOctet >= this.bcdChars.length) {
if (suppressException) {
return "";
} else {
throw new RangeError();
@ -7082,6 +7082,31 @@ GsmPDUHelperObject.prototype = {
return this.bcdChars.charAt(semiOctet);
},
/**
* Convert a semi-octet (number) to a GSM extended BCD char, or return empty
* string if invalid semiOctet and suppressException is set to true.
*
* @param semiOctet
* Nibble to be converted to.
* @param suppressException [optional]
* Suppress exception if invalid semiOctet and suppressException is set
* to true.
*
* @return GSM extended BCD char, or empty string.
*/
extendedBcdChars: "0123456789*#,;",
semiOctetToExtendedBcdChar: function(semiOctet, suppressException) {
if (semiOctet >= this.extendedBcdChars.length) {
if (suppressException) {
return "";
} else {
throw new RangeError();
}
}
return this.extendedBcdChars.charAt(semiOctet);
},
/**
* Read a *swapped nibble* binary coded decimal (BCD)
*
@ -7112,17 +7137,17 @@ GsmPDUHelperObject.prototype = {
},
/**
* Read a *swapped nibble* binary coded string (BCD)
* Read a *swapped nibble* binary coded decimal (BCD) string
*
* @param pairs
* Number of nibble *pairs* to read.
* @param [optional] supressException
* Supress exception if invalid semiOctet and supressException is set
* @param suppressException [optional]
* Suppress exception if invalid semiOctet and suppressException is set
* to true.
*
* @return The BCD string.
*/
readSwappedNibbleBcdString: function(pairs, supressException) {
readSwappedNibbleBcdString: function(pairs, suppressException) {
let str = "";
for (let i = 0; i < pairs; i++) {
let nibbleH = this.readHexNibble();
@ -7131,9 +7156,38 @@ GsmPDUHelperObject.prototype = {
break;
}
str += this.semiOctetToBcdChar(nibbleL, supressException);
str += this.semiOctetToBcdChar(nibbleL, suppressException);
if (nibbleH != 0x0F) {
str += this.semiOctetToBcdChar(nibbleH, supressException);
str += this.semiOctetToBcdChar(nibbleH, suppressException);
}
}
return str;
},
/**
* Read a *swapped nibble* extended binary coded decimal (BCD) string
*
* @param pairs
* Number of nibble *pairs* to read.
* @param suppressException [optional]
* Suppress exception if invalid semiOctet and suppressException is set
* to true.
*
* @return The BCD string.
*/
readSwappedNibbleExtendedBcdString: function(pairs, suppressException) {
let str = "";
for (let i = 0; i < pairs; i++) {
let nibbleH = this.readHexNibble();
let nibbleL = this.readHexNibble();
if (nibbleL == 0x0F) {
break;
}
str += this.semiOctetToExtendedBcdChar(nibbleL, suppressException);
if (nibbleH != 0x0F) {
str += this.semiOctetToExtendedBcdChar(nibbleH, suppressException);
}
}
@ -7605,7 +7659,7 @@ GsmPDUHelperObject.prototype = {
PDU_NL_IDENTIFIER_DEFAULT , PDU_NL_IDENTIFIER_DEFAULT );
return addr;
}
addr = this.readSwappedNibbleBcdString(len / 2);
addr = this.readSwappedNibbleExtendedBcdString(len / 2);
if (addr.length <= 0) {
if (DEBUG) this.context.debug("PDU error: no number provided");
return null;
@ -7955,7 +8009,7 @@ GsmPDUHelperObject.prototype = {
if (smscLength > 0) {
let smscTypeOfAddress = this.readHexOctet();
// Subtract the type-of-address octet we just read from the length.
msg.SMSC = this.readSwappedNibbleBcdString(smscLength - 1);
msg.SMSC = this.readSwappedNibbleExtendedBcdString(smscLength - 1);
if ((smscTypeOfAddress >> 4) == (PDU_TOA_INTERNATIONAL >> 4)) {
msg.SMSC = '+' + msg.SMSC;
}
@ -10424,7 +10478,7 @@ ICCPDUHelperObject.prototype = {
// TOA = TON + NPI
let toa = GsmPDUHelper.readHexOctet();
let number = GsmPDUHelper.readSwappedNibbleBcdString(len - 1);
let number = GsmPDUHelper.readSwappedNibbleExtendedBcdString(len - 1);
if (number.length <= 0) {
if (DEBUG) this.context.debug("No number provided");
return "";
@ -12668,11 +12722,12 @@ ICCRecordHelperObject.prototype = {
function callback() {
let Buf = this.context.Buf;
let RIL = this.context.RIL;
let GsmPDUHelper = this.context.GsmPDUHelper;
let strLen = Buf.readInt32();
let octetLen = strLen / 2;
RIL.iccInfo.iccid =
this.context.GsmPDUHelper.readSwappedNibbleBcdString(octetLen, true);
GsmPDUHelper.readSwappedNibbleBcdString(octetLen, true);
// Consumes the remaining buffer if any.
let unReadBuffer = this.context.Buf.getReadAvailable() -
this.context.Buf.PDU_HEX_OCTET_SIZE;
@ -13961,7 +14016,7 @@ SimRecordHelperObject.prototype = {
let buf = "";
for (let i = 0; i < reformat.length; i++) {
if (reformat[i] != 0xF) {
buf += GsmPDUHelper.semiOctetToBcdChar(reformat[i]);
buf += GsmPDUHelper.semiOctetToExtendedBcdChar(reformat[i]);
}
if (i === 2) {
// 0-2: MCC
@ -14118,7 +14173,7 @@ SimRecordHelperObject.prototype = {
let plmnEntry = {};
for (let i = 0; i < reformat.length; i++) {
if (reformat[i] != 0xF) {
buf += GsmPDUHelper.semiOctetToBcdChar(reformat[i]);
buf += GsmPDUHelper.semiOctetToExtendedBcdChar(reformat[i]);
}
if (i === 2) {
// 0-2: MCC
@ -14611,7 +14666,7 @@ ICCUtilsHelperObject.prototype = {
}
} else {
let GsmPDUHelper = this.context.GsmPDUHelper;
let wildChar = GsmPDUHelper.bcdChars.charAt(0x0d);
let wildChar = GsmPDUHelper.extendedBcdChars.charAt(0x0d);
// According to 3GPP TS 31.102 Sec. 4.2.59 and 3GPP TS 51.011 Sec. 10.3.42,
// the ME shall use this EF_OPL in association with the EF_PNN in place
// of any network name stored within the ME's internal list and any network

View File

@ -61,7 +61,7 @@ add_test(function test_read_dialling_number() {
return 0x81;
};
helper.readSwappedNibbleBcdString = function(len) {
helper.readSwappedNibbleExtendedBcdString = function(len) {
return str.substring(0, len);
};

View File

@ -714,10 +714,16 @@ add_test(function test_handling_iccid() {
do_check_eq(ril.iccInfo.iccid, expectedICCID);
}
// Invalid char at high nibbile + low nibbile contains 0xF.
// Invalid value 0xE at high nibbile + low nibbile contains 0xF.
do_test("9868002E90909F001519", "89860020909");
// Invalid char at low nibbile.
do_test("986800E2909090001519", "8986002090909005191");
// Invalid value 0xD at low nibbile.
do_test("986800D2909090001519", "8986002090909005191");
// Invalid value 0xC at low nibbile.
do_test("986800C2909090001519", "8986002090909005191");
// Invalid value 0xB at low nibbile.
do_test("986800B2909090001519", "8986002090909005191");
// Invalid value 0xA at low nibbile.
do_test("986800A2909090001519", "8986002090909005191");
// Valid ICCID.
do_test("98101430121181157002", "89014103211118510720");