Text   |  XML   |  ReML   |   Visible Warnings:

Format String  at packet-asn1.c:1736

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

decode_asn1_sequence

(/home/sate/Testcases/c/cve/wireshark-1.2.0/plugins/asn1/packet-asn1.c)expand/collapse
Show more  
 935  decode_asn1_sequence(tvbuff_t *tvb, guint offset, guint tlen, proto_tree *pt, int level)
 936  {
 937    ASN1_SCK asn1;
 938    guint ret, cls, con, tag, len, boffset, soffset, eos;
 939    gboolean def;
 940    guint value;
 941    const char *clsstr, *constr, *tagstr;
 942    char tagbuf[BUFLM];
 943    char lenbuf[BUFLM];
 944    char nnbuf[BUFLS];
 945    proto_tree *ti, *pt2;
 946    proto_item *hidden_item;
 947    guchar *octets, *bits, unused;
 948    subid_t *oid;
 949    /* the debugging formats */
 950    static char textfmt_d[] = "off=%d: [%s %s %s] (%s)%s: %d%s";          /* decimal */
 951    static char textfmt_e[] = "off=%d: [%s %s %s] (%s)%s: %d:%s%s";       /* enum */
 952    static char textfmt_s[] = "off=%d: [%s %s %s] (%s)%s: '%s'%s";        /* octet string */
 953    static char textfmt_b[] = "off=%d: [%s %s %s] (%s)%s: %s:%s%s";       /* bit field */
 954    static char textfmt_c[] = "off=%d: [%s %s %s] (%s)%s%s%s";            /* constructed */
 955    static char matchind[] = " ~"; /* indication of possible match */
 956    const char *name, *ename, *tname;
 957    char *oname;
 958    PDUprops props;
 959   
 960    ti = 0;                       /* suppress gcc warning */
 961   
 962    soffset = offset; /* where this sequence starts */
 963    eos = offset + tlen;
 964    while (offset < eos) {        /* while this entity has not ended... */
 965            boffset = offset;
 966            asn1_open(&asn1, tvb, offset);
 967            ret = asn1_header_decode(&asn1, &cls, &con, &tag, &def, &len);
 968            asn1_close(&asn1, &offset); /* mark current position */
 969            if (ret != ASN1_ERR_NOERROR) {
 970                  proto_tree_add_text(pt, tvb, offset, 1, "ASN1 ERROR: %s", asn1_err_to_str(ret) );
 971                  break;
 972            }
 973   
 974            getPDUprops(&props, boffset, cls, tag, con);
 975            name = props.name;
 976            tname = props.typename;
 977            if (asn1_full)
 978                    name = &props.fullname[pabbrev_pdu_len];      /* no abbrev.pduname */
 979            if (asn1_debug) {     /* show both names */
 980                    g_sprintf(fieldname, "%s[%s]", props.name, props.fullname);
 981                    name = fieldname;
 982            }
 983   
 984            clsstr = asn1_cls[cls];
 985            constr = asn1_con[con];
 986            if ((cls == BER_CLASS_UNI) && ( tag < 32 )) {
 987                    tagstr = asn1_tag[tag];
 988            } else {
 989                    g_snprintf(tagbuf, sizeof(tagbuf), "%ctag%d", tag_class[cls], tag);
 990                    tagstr = tagbuf;
 991            }
 992   
 993            len = checklength(len, def, cls, tag, lenbuf, sizeof(lenbuf));
 994   
 995            if (def) {
 996                    g_snprintf(nnbuf, sizeof(nnbuf), "NN%d", len);
 997            } else {
 998                    strncpy(nnbuf, "NN-", sizeof(nnbuf));
 999                                  /* make sure we get an exception if we run off the end! */
 1000                    len = tvb_length_remaining(tvb, offset) + 1;
 1001            }
 1002            if ( ( ! asn1_debug) && (props.flags & OUT_FLAG_noname) ) {
 1003                    /* just give type name if we don't know any better */
 1004                    tname = tagstr;
 1005                    name = nnbuf; /* this is better than just empty.... */
 1006            }
 1007   
 1008  #ifdef NEST 
 1009            taglist[level].cls = cls;
 1010            taglist[level].tag = tag;
 1011  #endif /* NEST */
 1012   
 1013            oname  = 0;
 1014            if (level >= MAX_NEST) { /* nesting too deep..., handle as general octet string */
 1015                  cls = BER_CLASS_UNI;
 1016                  tag = BER_UNI_TAG_GeneralString;
 1017                  oname = g_malloc(strlen(name) + 32);
 1018                  g_sprintf(oname, "%s ** nesting cut off **", name);
 1019                  name = oname;
 1020            }
 1021            switch(cls) {
 1022              case BER_CLASS_UNI: /* fprintf(stderr, "Universal\n"); */
 1023                switch(tag) {
 1024                  case BER_UNI_TAG_INTEGER:
 1025                        ret = asn1_int32_value_decode(&asn1, len, &value); /* read value */
 1026                        asn1_close(&asn1, &offset); /* mark where we are now */
 1027                        if (asn1_debug) {
 1028                                if ( (props.value_id == -1) ||
 1029                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1030                                          /* unknown or unexpected: just text */
 1031                                          proto_tree_add_text(pt, tvb, boffset,
 1032                                                          offset - boffset, textfmt_d, boffset,
 1033                                                          clsstr, constr, tagstr, tname, name, value,
 1034                                                          empty);
 1035                                else {
 1036                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1037                                                          offset - boffset, value, textfmt_d, boffset,
 1038                                                          clsstr, constr, tagstr, tname, name, value,
 1039                                                          matchind);
 1040                                          if (props.type_id != -1) {
 1041                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1042                                                                  boffset, offset - boffset, value);
 1043                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1044                                          }
 1045                                }
 1046                        } else {
 1047                                if ( (props.value_id == -1) ||
 1048                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1049                                          /* unknown or unexpected, just text */
 1050                                          proto_tree_add_text(pt, tvb, boffset,
 1051                                                          offset - boffset,
 1052                                                          "(%s)%s: %d", tname, name, value);
 1053                                else {
 1054                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1055                                                          offset - boffset, value,
 1056                                                          "(%s)%s: %d ~", tname, name, value);
 1057                                          if (props.type_id != -1){
 1058                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1059                                                                  boffset, offset - boffset, value);
 1060                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1061                                          }
 1062                                }
 1063                        }
 1064                        break;
 1065   
 1066                  case BER_UNI_TAG_ENUMERATED:
 1067                        ret = asn1_int32_value_decode(&asn1, len, &value); /* read value */
 1068                        asn1_close(&asn1, &offset); /* mark where we are now */
 1069                        ename = getPDUenum(&props, boffset, cls, tag, value);
 1070                        if (asn1_debug) {
 1071                                if ( (props.value_id == -1) ||
 1072                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1073                                          /* unknown or unexpected, just text */
 1074                                          proto_tree_add_text(pt, tvb, boffset,
 1075                                                          offset - boffset,
 1076                                                          textfmt_e, boffset, clsstr, constr, tagstr,
 1077                                                          tname, name, value, ename, empty);
 1078                                else {
 1079                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1080                                                          offset - boffset, value,
 1081                                                          textfmt_e, boffset, clsstr, constr, tagstr,
 1082                                                          tname, name, value, ename, matchind);
 1083                                          if (props.type_id != -1){
 1084                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1085                                                                  boffset, offset - boffset, value);
 1086                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1087                                          }
 1088                                }
 1089                        } else {
 1090                                if ( (props.value_id == -1) ||
 1091                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1092                                          /* unknown or unexpected, just text */
 1093                                          proto_tree_add_text(pt, tvb, boffset,
 1094                                                          offset - boffset,
 1095                                                          "(%s)%s: %d:%s", tname, name, value, ename);
 1096                                else {
 1097                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1098                                                          offset - boffset, value,
 1099                                                          "(%s)%s: %d:%s ~", tname, name, value, ename);
 1100                                          if (props.type_id != -1){
 1101                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1102                                                                  boffset, offset - boffset, value);
 1103                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1104                                          }
 1105                                }
 1106                        }
 1107                        break;
 1108   
 1109                  case BER_UNI_TAG_BOOLEAN:
 1110                        ret = asn1_bool_decode(&asn1, len, (gboolean *)&value); /* read value */
 1111                        asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1112                        if (asn1_debug) {
 1113                                if ( (props.value_id == -1) ||
 1114                                     (tbl_types_wireshark[props.type] != FT_BOOLEAN) )
 1115                                          /* unknown or unexpected, just text */
 1116                                          proto_tree_add_text(pt, tvb, boffset,
 1117                                                          offset - boffset,
 1118                                                          textfmt_s, boffset, clsstr, constr, tagstr,
 1119                                                          tname, name, value? "true" : "false", empty);
 1120                                else {
 1121                                          proto_tree_add_boolean_format(pt, props.value_id, tvb, boffset,
 1122                                                          offset - boffset, value != 0,
 1123                                                          textfmt_s, boffset, clsstr, constr, tagstr,
 1124                                                          tname, name, value? "true" : "false", matchind);
 1125                                          if (props.type_id != -1){
 1126                                                  hidden_item = proto_tree_add_boolean(pt, props.type_id, tvb,
 1127                                                                  boffset, offset - boffset, value != 0);
 1128                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1129                                          }
 1130                                }
 1131                        } else {
 1132                                if ( (props.value_id == -1) ||
 1133                                     (tbl_types_wireshark[props.type] != FT_BOOLEAN) )
 1134                                          /* unknown or unexpected, just text */
 1135                                          proto_tree_add_text(pt, tvb, boffset,
 1136                                                          offset - boffset,
 1137                                                          "(%s)%s: %s", tname, name,
 1138                                                          value? "true" : "false");
 1139                                else {
 1140                                          proto_tree_add_boolean_format(pt, props.value_id, tvb, boffset,
 1141                                                          offset - boffset, value != 0,
 1142                                                          "(%s)%s: %s ~", tname, name,
 1143                                                          value? "true" : "false");
 1144                                          if (props.type_id != -1){
 1145                                                  hidden_item = proto_tree_add_boolean(pt, props.type_id, tvb,
 1146                                                                  boffset, offset - boffset, value != 0);
 1147                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1148                                          }
 1149                                }
 1150                        }
 1151                        break;
 1152   
 1153                  case BER_UNI_TAG_OCTETSTRING:
 1154                  case BER_UNI_TAG_NumericString:
 1155                  case BER_UNI_TAG_PrintableString:
 1156                  case BER_UNI_TAG_TeletexString:
 1157                  case BER_UNI_TAG_IA5String:
 1158                  case BER_UNI_TAG_GeneralString:
 1159                  case BER_UNI_TAG_UTCTime:
 1160                  case BER_UNI_TAG_GeneralizedTime:
 1161                          /* read value, \0 terminated */
 1162                        ret = asn1_string_value_decode(&asn1, len, &octets);
 1163                        asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1164                        ename = showoctets(octets, len, (tag == BER_UNI_TAG_OCTETSTRING) ? 4 : 0 );
 1165                        if (asn1_debug) {
 1166                                if ( (props.value_id == -1) ||
 1167                                     (tbl_types_wireshark[props.type] != FT_STRINGZ) )
 1168                                          /* unknown or unexpected, just text */
 1169                                          proto_tree_add_text(pt, tvb, boffset,
 1170                                                          offset - boffset,
 1171                                                          textfmt_s, boffset, clsstr, constr, tagstr,
 1172                                                          tname, name, ename, empty);
 1173                                else {
 1174                                          proto_tree_add_string_format(pt, props.value_id, tvb, boffset,
 1175                                                          offset - boffset, octets, /* \0 termnated */
 1176                                                          textfmt_s, boffset, clsstr, constr, tagstr,
 1177                                                          tname, name, ename, matchind);
 1178                                          if (props.type_id != -1){
 1179                                                  hidden_item = proto_tree_add_string(pt, props.type_id, tvb,
 1180                                                                  boffset, offset - boffset, octets);
 1181                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1182                                          }
 1183                                }
 1184                        } else {
 1185                                if ( (props.value_id == -1) ||
 1186                                     (tbl_types_wireshark[props.type] != FT_STRINGZ) )
 1187                                          /* unknown or unexpected, just text */
 1188                                          proto_tree_add_text(pt, tvb, boffset,
 1189                                                          offset - boffset,
 1190                                                          "(%s)%s: %s", tname, name, ename);
 1191                                else {
 1192                                          proto_tree_add_string_format(pt, props.value_id, tvb, boffset,
 1193                                                          offset - boffset, octets, /* \0 terminated */
 1194                                                          "(%s)%s: %s ~", tname, name, ename);
 1195                                          if (props.type_id != -1){
 1196                                                  hidden_item = proto_tree_add_string(pt, props.type_id, tvb,
 1197                                                                  boffset, offset - boffset, octets);
 1198                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1199                                          }
 1200                                }
 1201                        }
 1202                        g_free(octets);
 1203                        g_free( (gpointer) ename);
 1204                        break;
 1205   
 1206                  case BER_UNI_TAG_BITSTRING:
 1207                        ret = asn1_bits_decode(&asn1, len, &bits, &con, &unused); /* read value */
 1208                        asn1_close(&asn1, &offset); /* mark where we are now */
 1209                        ename = showbitnames(bits, (con*8)-unused, &props, offset);
 1210                        if (asn1_debug) {
 1211                                if ( (props.value_id == -1) ||
 1212                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1213                                          /* unknown or unexpected, just text */
 1214                                          proto_tree_add_text(pt, tvb, boffset,
 1215                                                          offset - boffset,
 1216                                                          textfmt_b, boffset, clsstr, constr, tagstr,
 1217                                                          tname, name,
 1218                                                          showbits(bits, (con*8)-unused), ename, empty);
 1219                                else {
 1220                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1221                                                          offset - boffset, *bits, /* XXX length ? XXX */
 1222                                                          textfmt_b, boffset, clsstr, constr, tagstr,
 1223                                                          tname, name,
 1224                                                          showbits(bits, (con*8)-unused),ename, matchind);
 1225                                          if (props.type_id != -1){
 1226                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1227                                                                  boffset, offset - boffset, *bits);
 1228                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1229                                          }
 1230                                }
 1231   
 1232                        } else {
 1233                                if ( (props.value_id == -1) ||
 1234                                     (tbl_types_wireshark[props.type] != FT_UINT32) )
 1235                                          /* unknown or unexpected, just text */
 1236                                          proto_tree_add_text(pt, tvb, boffset,
 1237                                                          offset - boffset,
 1238                                                          "(%s)%s: %s:%s", tname, name,
 1239                                                          showbits(bits, (con*8)-unused), ename);
 1240                                else {
 1241                                          proto_tree_add_uint_format(pt, props.value_id, tvb, boffset,
 1242                                                          offset - boffset, *bits, /* XXX length ? XXX */
 1243                                                          "(%s)%s: %s:%s ~", tname, name,
 1244                                                          showbits(bits, (con*8)-unused), ename);
 1245                                          if (props.type_id != -1){
 1246                                                  hidden_item = proto_tree_add_uint(pt, props.type_id, tvb,
 1247                                                                  boffset, offset - boffset, *bits);
 1248                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1249                                          }
 1250                                }
 1251                        }
 1252                        g_free(bits);
 1253                        break;
 1254   
 1255                  case BER_UNI_TAG_SET:
 1256                  case BER_UNI_TAG_SEQUENCE:
 1257                                  /* show full sequence length */
 1258                        if (asn1_debug) {
 1259                                ename = empty;
 1260                                if ( (props.flags & OUT_FLAG_dontshow) || asn1_full)
 1261                                        ename = ", noshow";
 1262                                if ( (props.flags & OUT_FLAG_constructed))
 1263                                        ename = ", unexpected constructed";
 1264   
 1265                                if (props.value_id == -1)
 1266                                        ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1267                                                               textfmt_c, boffset, clsstr, constr, tagstr,
 1268                                                               tname, name, ename, empty);
 1269                                else {
 1270                                        ti = proto_tree_add_item(pt, props.value_id, tvb,
 1271                                                                boffset, 1, TRUE);
 1272                                        /* change te text to to what I really want */
 1273                                        proto_item_set_text(ti, textfmt_c, boffset, clsstr, constr,
 1274                                                               tagstr, tname, name, ename, matchind);
 1275                                            if (props.type_id != -1){
 1276                                                hidden_item = proto_tree_add_item(pt, props.type_id, tvb,
 1277                                                                boffset, 1, TRUE);
 1278                                                    PROTO_ITEM_SET_HIDDEN(hidden_item);
 1279                                            }
 1280                                }
 1281                        } else {
 1282                                if (props.value_id == -1) {
 1283                                        if ( (! asn1_full) && ((props.flags & OUT_FLAG_dontshow) == 0) )
 1284                                                ti = proto_tree_add_text(pt, tvb, boffset,
 1285                                                                         offset - boffset + len,
 1286                                                                         "(%s)%s", tname, name);
 1287                                } else {
 1288                                        if ( (! asn1_full) && ((props.flags & OUT_FLAG_dontshow) == 0) )
 1289                                                ti = proto_tree_add_none_format(pt, props.value_id, tvb,
 1290                                                                         boffset, offset - boffset + len,
 1291                                                                         "(%s)%s ~", tname, name);
 1292                                        else {
 1293                                                /* don't care about the text */
 1294                                                ti = hidden_item = proto_tree_add_item(pt, props.value_id, tvb,
 1295                                                            boffset, 1, TRUE);
 1296                                                    PROTO_ITEM_SET_HIDDEN(hidden_item);
 1297                                        }
 1298                                            if (props.type_id != -1){
 1299                                                hidden_item = proto_tree_add_item(pt, props.type_id, tvb,
 1300                                                            boffset, 1, TRUE);
 1301                                                    PROTO_ITEM_SET_HIDDEN(hidden_item);
 1302                                            }
 1303                                }
 1304                        }
 1305                        if (len == 0) return offset; /* don't recurse if offset isn't going to change */
 1306   
 1307                        if ( ( ! asn1_full) && (asn1_debug || ((props.flags & OUT_FLAG_dontshow) == 0)))
 1308                                pt2 = proto_item_add_subtree(ti, ett_seq[level]);
 1309                        else 
 1310                                pt2 = pt;
 1311   
 1312                        offset = decode_asn1_sequence(tvb, offset, len, pt2, level+1); /* recurse */
 1313   
 1314                        if ( ( ! asn1_full) && (asn1_debug || ((props.flags & OUT_FLAG_dontshow) == 0)))
 1315                                proto_item_set_len(ti, offset - boffset);
 1316   
 1317                        break;
 1318   
 1319                  case BER_UNI_TAG_EOC:
 1320                        if (asn1_debug) { /* don't show if not debugging */
 1321                                proto_tree_add_text(pt, tvb, boffset, offset - boffset, textfmt_d,
 1322                                                    boffset, clsstr, constr, tagstr, tname, name,
 1323                                                    offset - soffset, empty);
 1324                        }
 1325                        getPDUprops(&props, soffset, ASN1_EOI, 1, 0); /* mark end of this sequence */
 1326                        return offset;
 1327   
 1328                  case BER_UNI_TAG_OID:
 1329                        ret = asn1_oid_value_decode(&asn1, len, &oid, &con);
 1330                        asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1331                        ename = showoid(oid, con);
 1332                        if (asn1_debug) {
 1333                                if ( (props.value_id == -1) ||
 1334                                     (tbl_types_wireshark[props.type] != FT_BYTES) )
 1335                                        /* unknown or unexpected, just text */
 1336                                        proto_tree_add_text(pt, tvb, boffset, offset - boffset, textfmt_s,
 1337                                                            boffset, clsstr, constr, tagstr, tname, name,
 1338                                                            ename, empty);
 1339                                else {
 1340                                        proto_tree_add_bytes_format(pt, props.value_id, tvb, boffset,
 1341                                                                   offset - boffset, ename,/* XXX length?*/
 1342                                                                   "(%s)%s: %s ~", tname, name, ename);
 1343                                            if (props.type_id != -1){
 1344                                                    hidden_item = proto_tree_add_bytes(pt, props.type_id, tvb,
 1345                                                                  boffset, offset - boffset, ename);
 1346                                                    PROTO_ITEM_SET_HIDDEN(hidden_item);
 1347                                            }
 1348                                }
 1349                        } else {
 1350                                if ( (props.value_id == -1) ||
 1351                                     (tbl_types_wireshark[props.type] != FT_BYTES) )
 1352                                          /* unknown or unexpected, just text */
 1353                                          proto_tree_add_text(pt, tvb, boffset,
 1354                                                          offset - boffset,
 1355                                                          "(%s)%s: %s", tname, name, ename);
 1356                                else {
 1357                                          proto_tree_add_bytes_format(pt, props.value_id, tvb, boffset,
 1358                                                          offset - boffset, ename, /* XXX length ? */
 1359                                                          "(%s)%s: %s ~", tname, name, ename);
 1360                                          if (props.type_id != -1){
 1361                                                  hidden_item = proto_tree_add_bytes(pt, props.type_id, tvb,
 1362                                                                  boffset, offset - boffset, ename);
 1363                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1364                                          }
 1365                                }
 1366                        }
 1367                        g_free(oid);
 1368                        break;
 1369   
 1370                  case BER_UNI_TAG_NULL:
 1371                        if (asn1_debug) {
 1372                                proto_tree_add_text(pt, tvb, boffset, offset - boffset + len, textfmt_s,
 1373                                                    boffset, clsstr, constr, tagstr, tname, name,
 1374                                                    "[NULL]", empty);
 1375                        } else {
 1376                                proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1377                                                    "(%s)%s: [NULL]", tname, name);
 1378                        }
 1379                        offset += len; /* skip value ... */
 1380                        break;
 1381   
 1382                  case BER_UNI_TAG_ObjectDescriptor:
 1383                  case ASN1_EXT:
 1384                  case BER_UNI_TAG_REAL:
 1385                  case BER_UNI_TAG_VideotexString:
 1386                  case BER_UNI_TAG_GraphicString:
 1387                  case BER_UNI_TAG_VisibleString:
 1388   
 1389                  default:
 1390                        if (asn1_debug) {
 1391                                ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1392                                                         textfmt_s, boffset, clsstr, constr, tagstr,
 1393                                                         tname, name, lenbuf, empty);
 1394                        } else {
 1395                                ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1396                                                         "(%s)%s: %s bytes", tname, name, lenbuf);
 1397                        }
 1398                        proto_item_append_text(ti, " *"); /* indicate default is used */
 1399                        offset += len; /* skip value ... */
 1400                        break;
 1401                };
 1402                break;
 1403   
 1404              case BER_CLASS_CON:         /* fprintf(stderr, "Context\n"); */
 1405              case BER_CLASS_APP:         /* fprintf(stderr, "Application\n"); */
 1406              case BER_CLASS_PRI:         /* fprintf(stderr, "Private\n"); */
 1407   
 1408                    if (def && !con) {
 1409                          if (props.value_id == -1) /* type unknown, handle as string */
 1410                                  goto dostring;
 1411                          switch(props.type) {
 1412                                  /* this is via the asn1 description, don't trust the length */
 1413                          case TBL_INTEGER:
 1414                                  if (len > 4)
 1415                                          goto dostring;
 1416                                  ret = asn1_int32_value_decode(&asn1, len, (gint32 *)&value); /* read value */
 1417                                  asn1_close(&asn1, &offset); /* mark where we are now */
 1418                                  if (asn1_debug) {
 1419                                          if ( (props.value_id == -1) ||
 1420                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1421                                                  /* unknown or unexpected, just text */
 1422                                                  proto_tree_add_text(pt, tvb,
 1423                                                              boffset, offset - boffset,
 1424                                                              textfmt_d, boffset, clsstr, constr,
 1425                                                              tagstr, tname, name, value, empty);
 1426                                          else {
 1427                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1428                                                              boffset, offset - boffset, value,
 1429                                                              textfmt_d, boffset, clsstr, constr,
 1430                                                              tagstr, tname, name, value, matchind);
 1431                                                  if (props.type_id != -1){
 1432                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1433                                                                  tvb, boffset, offset - boffset, value);
 1434                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1435                                                  }
 1436                                          }
 1437                                  } else {
 1438                                          if ( (props.value_id == -1) ||
 1439                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1440                                                  /* unknown or unexpected, just text */
 1441                                                  proto_tree_add_text(pt, tvb,
 1442                                                              boffset, offset - boffset,
 1443                                                              "(%s)%s: %d", tname, name, value);
 1444                                          else {
 1445                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1446                                                              boffset, offset - boffset, value,
 1447                                                              "(%s)%s: %d ~", tname, name, value);
 1448                                                  if (props.type_id != -1){
 1449                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1450                                                                  tvb, boffset, offset - boffset, value);
 1451                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1452                                                  }
 1453                                          }
 1454                                  }
 1455                                  break;
 1456   
 1457                          case TBL_ENUMERATED:
 1458                                  if (len > 4)
 1459                                          goto dostring;
 1460                                  ret = asn1_int32_value_decode(&asn1, len, &value); /* read value */
 1461                                  asn1_close(&asn1, &offset); /* mark where we are now */
 1462                                  ename = getPDUenum(&props, boffset, cls, tag, value);
 1463                                  if (asn1_debug) {
 1464                                          if ( (props.value_id == -1) ||
 1465                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1466                                                  /* unknown or unexpected, just text */
 1467                                                  proto_tree_add_text(pt, tvb,
 1468                                                             boffset, offset - boffset,
 1469                                                             textfmt_e, boffset, clsstr, constr,
 1470                                                             tagstr, tname, name, value, ename, empty);
 1471                                          else {
 1472                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1473                                                             boffset, offset - boffset, value,
 1474                                                             textfmt_e, boffset, clsstr, constr,
 1475                                                             tagstr, tname, name, value, ename, matchind);
 1476                                                  if (props.type_id != -1){
 1477                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1478                                                                  tvb, boffset, offset - boffset, value);
 1479                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1480                                                  }
 1481                                          }
 1482                                  } else {
 1483                                          if ( (props.value_id == -1) ||
 1484                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1485                                                  /* unknown or unexpected, just text */
 1486                                                  proto_tree_add_text(pt, tvb,
 1487                                                             boffset, offset - boffset,
 1488                                                             "(%s)%s: %d:%s", tname, name, value, ename);
 1489                                          else {
 1490                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1491                                                            boffset, offset - boffset, value,
 1492                                                            "(%s)%s: %d:%s ~", tname, name, value, ename);
 1493                                                  if (props.type_id != -1){
 1494                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1495                                                                  tvb, boffset, offset - boffset, value);
 1496                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1497                                                  }
 1498                                          }
 1499                                  }
 1500                                  break;
 1501                          case TBL_BITSTRING:
 1502                                  if (len > (1+4)) /* max 32 bits ...?.. */
 1503                                          goto dostring;
 1504                                                                  /* read value */
 1505                                  ret = asn1_bits_decode(&asn1, len, &bits, &con, &unused);
 1506                                  asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1507                                  ename = showbitnames(bits, (con*8)-unused, &props, offset);
 1508                                  if (asn1_debug) {
 1509                                          if ( (props.value_id == -1) ||
 1510                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1511                                                  /* unknown or unexpected, just text */
 1512                                                  proto_tree_add_text(pt, tvb,
 1513                                                              boffset, offset - boffset,
 1514                                                              textfmt_b, boffset, clsstr, constr,
 1515                                                              tagstr, tname, name,
 1516                                                              showbits(bits, (con*8)-unused), ename,
 1517                                                              empty);
 1518                                          else {
 1519                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1520                                                              boffset, offset - boffset, *bits,
 1521                                                              textfmt_b, boffset, clsstr, constr,
 1522                                                              tagstr, tname, name,
 1523                                                              showbits(bits, (con*8)-unused), ename,
 1524                                                              matchind);
 1525                                                  if (props.type_id != -1){
 1526                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1527                                                                   tvb, boffset, offset - boffset, *bits);
 1528                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1529                                                  }
 1530                                          }
 1531                                  } else {
 1532                                          if ( (props.value_id == -1) ||
 1533                                               (tbl_types_wireshark[props.type] != FT_UINT32) )
 1534                                                  /* unknown or unexpected, just text */
 1535                                                  proto_tree_add_text(pt, tvb, boffset, offset - boffset,
 1536                                                              "(%s)%s: %s:%s", tname, name,
 1537                                                              showbits(bits, (con*8)-unused), ename);
 1538                                          else {
 1539                                                  proto_tree_add_uint_format(pt, props.value_id, tvb,
 1540                                                              boffset, offset - boffset, *bits,
 1541                                                              "(%s)%s: %s:%s ~", tname, name,
 1542                                                              showbits(bits, (con*8)-unused), ename);
 1543                                                  if (props.type_id != -1){
 1544                                                          hidden_item = proto_tree_add_uint(pt, props.type_id,
 1545                                                                  tvb, boffset, offset - boffset, *bits);
 1546                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1547                                                  }
 1548                                          }
 1549                                  }
 1550                                  g_free(bits);
 1551                                  break;
 1552                          case TBL_BOOLEAN:
 1553                                  if (len > 1)
 1554                                          goto dostring;
 1555                                  ret = asn1_bool_decode(&asn1, len, (gboolean *)&value); /* read value */
 1556                                  asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1557                                  if (asn1_debug) {
 1558                                          if ( (props.value_id == -1) ||
 1559                                               (tbl_types_wireshark[props.type] != FT_BOOLEAN) )
 1560                                                  /* unknown or unexpected, just text */
 1561                                                  proto_tree_add_text(pt, tvb,
 1562                                                              boffset, offset - boffset,
 1563                                                              textfmt_s, boffset, clsstr, constr,
 1564                                                              tagstr, tname, name,
 1565                                                              value? "true" : "false", empty);
 1566                                          else {
 1567                                                  proto_tree_add_boolean_format(pt, props.value_id,  tvb,
 1568                                                              boffset, offset - boffset, value != 0,
 1569                                                              textfmt_s, boffset, clsstr, constr,
 1570                                                              tagstr, tname, name,
 1571                                                              value? "true" : "false", matchind);
 1572                                                  if (props.type_id != -1){
 1573                                                          hidden_item = proto_tree_add_boolean(pt, props.type_id,
 1574                                                            tvb, boffset, offset - boffset, value != 0);
 1575                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1576                                                  }
 1577                                          }
 1578                                  } else {
 1579                                          if ( (props.value_id == -1) ||
 1580                                               (tbl_types_wireshark[props.type] != FT_BOOLEAN) )
 1581                                                  /* unknown or unexpected, just text */
 1582                                                  proto_tree_add_text(pt, tvb,
 1583                                                              boffset, offset - boffset,
 1584                                                              "(%s)%s: %s", tname, name,
 1585                                                              value? "true" : "false");
 1586                                          else {
 1587                                                  proto_tree_add_boolean_format(pt, props.value_id, tvb,
 1588                                                              boffset, offset - boffset, value != 0,
 1589                                                              "(%s)%s: %s ~", tname, name,
 1590                                                              value? "true" : "false");
 1591                                                  if (props.type_id != -1){
 1592                                                          hidden_item = proto_tree_add_boolean(pt, props.type_id,
 1593                                                            tvb, boffset, offset - boffset, value != 0);
 1594                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1595                                                  }
 1596                                          }
 1597                                  }
 1598                                  break;
 1599                          case TBL_NULL:
 1600                                  if (len > 0)
 1601                                          goto dostring;
 1602                                  if (asn1_debug) {
 1603                                          proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1604                                                              textfmt_s, boffset, clsstr, constr,
 1605                                                              tagstr, tname, name, "[NULL]", empty);
 1606                                  } else {
 1607                                          proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1608                                                              "(%s)%s: [NULL]", tname, name);
 1609                                  }
 1610                                  offset += len; /* skip value ... */
 1611                                  break;
 1612                          default:
 1613                          dostring:
 1614                                  props.value_id = -1; /* unlikely this is correct, dont use it */
 1615                                  /* fallthrough */
 1616                          case TBL_OCTETSTRING:
 1617                                  /* defined length, not constructed, must be a string.... */
 1618                                  ret = asn1_string_value_decode(&asn1, len, &octets); /* read value */
 1619                                  asn1_close(&asn1, (gint *)&offset); /* mark where we are now */
 1620                                  ename = showoctets(octets, len, 2); /* convert octets to printable */
 1621                                  if (asn1_debug) {
 1622                                          if ( (props.value_id == -1) ||
 1623                                               (tbl_types_wireshark[props.type] != FT_STRINGZ) )
 1624                                                  /* unknown or unexpected, just text */
 1625                                                  proto_tree_add_text(pt, tvb,
 1626                                                              boffset, offset - boffset,
 1627                                                              textfmt_s, boffset, clsstr, constr,
 1628                                                              tagstr, tname, name, ename, empty);
 1629                                          else {
 1630                                                  proto_tree_add_string_format(pt, props.value_id, tvb,
 1631                                                              boffset, offset - boffset, (gchar *)octets, /* XXX */
 1632                                                              textfmt_s, boffset, clsstr, constr,
 1633                                                              tagstr, tname, name, ename, matchind);
 1634                                                  if (props.type_id != -1){
 1635                                                          hidden_item = proto_tree_add_string(pt, props.type_id,
 1636                                                                  tvb, boffset, offset - boffset, (gchar *)octets);
 1637                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1638                                                  }
 1639                                          }
 1640                                  } else {
 1641                                          if ( (props.value_id == -1) ||
 1642                                               (tbl_types_wireshark[props.type] != FT_STRINGZ) )
 1643                                                  /* unknown or unexpected, just text */
 1644                                                  proto_tree_add_text(pt, tvb, boffset, offset - boffset,
 1645                                                              "(%s)%s: %s", tname, name, ename);
 1646                                          else {
 1647                                                  proto_tree_add_string_format(pt, props.value_id, tvb,
 1648                                                              boffset, offset - boffset, (gchar *)octets, /* XXX */
 1649                                                              "(%s)%s: %s ~", tname, name, ename);
 1650                                                  if (props.type_id != -1){
 1651                                                          hidden_item = proto_tree_add_string(pt, props.type_id,
 1652                                                                  tvb, boffset, offset - boffset, (gchar *)octets);
 1653                                                          PROTO_ITEM_SET_HIDDEN(hidden_item);
 1654                                                  }
 1655                                          }
 1656                                  }
 1657                                  g_free(octets);
 1658                                  g_free( (gpointer) ename);
 1659                                  break;
 1660                          }
 1661                    } else {
 1662                          /* indefinite length or constructed.... must be a sequence .... */
 1663                          /* show full sequence length */
 1664                          if (asn1_debug) {
 1665                                  ename = empty;
 1666                                  if ( (props.flags & OUT_FLAG_dontshow) || asn1_full)
 1667                                          ename = ", noshow";
 1668                                  if ( (props.flags & OUT_FLAG_constructed))
 1669                                          ename = ", unexpected constructed";
 1670   
 1671                                  if (props.value_id == -1)
 1672                                        ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1673                                                                   textfmt_c, boffset, clsstr, constr,
 1674                                                                   tagstr, tname, name, ename, empty);
 1675                                  else {
 1676                                        ti = proto_tree_add_item(pt, props.value_id, tvb,
 1677                                                                boffset, 1, TRUE);
 1678                                        /* change te text to to what I really want */
 1679                                        if (ti) {
 1680                                          proto_item_set_text(ti, textfmt_c, boffset, clsstr, constr,
 1681                                                               tagstr, tname, name, ename, matchind);
 1682                                          if (props.type_id != -1){
 1683                                                hidden_item = proto_tree_add_item(pt, props.type_id, tvb,
 1684                                                                boffset, 1, TRUE);
 1685                                                    PROTO_ITEM_SET_HIDDEN(hidden_item);
 1686                                          }
 1687                                        } else {
 1688                                          ti = proto_tree_add_text(pt, tvb, boffset,
 1689                                                                   offset - boffset + len,
 1690                                                                   textfmt_c, boffset, clsstr, constr,
 1691                                                                   tagstr, tname, name, ename, empty);
 1692                                        }
 1693                                  }
 1694                          } else {
 1695                                  if (props.value_id == -1) {
 1696                                          if ( ( ! asn1_full) && ((props.flags & OUT_FLAG_dontshow) == 0))
 1697                                                  ti = proto_tree_add_text(pt, tvb, boffset,
 1698                                                           offset - boffset + len, "(%s)%s", tname, name);
 1699                                  } else {
 1700                                          if ( ( ! asn1_full) && ((props.flags & OUT_FLAG_dontshow) == 0))
 1701                                                  ti = proto_tree_add_none_format(pt, props.value_id, tvb,
 1702                                                                  boffset, 1,
 1703                                                                  "(%s)%s ~", tname, name);
 1704                                          else {
 1705                                                  /* don't care about the text */
 1706                                                  ti = proto_tree_add_item(pt, props.value_id,
 1707                                                               tvb,  boffset, 1, TRUE);
 1708                                                  PROTO_ITEM_SET_HIDDEN(ti);
 1709                                          }
 1710                                          if (props.type_id != -1){
 1711                                                  hidden_item = proto_tree_add_item(pt, props.type_id,
 1712                                                               tvb,  boffset, 1, TRUE);
 1713                                                  PROTO_ITEM_SET_HIDDEN(hidden_item);
 1714                                          }
 1715                                  }
 1716                          }
 1717   
 1718                          if (len == 0) return offset; /* don't recurse if offset isn't going to change */
 1719   
 1720                          if ( ( ! asn1_full) && (asn1_debug || ((props.flags & OUT_FLAG_dontshow) == 0)))
 1721                                  pt2 = proto_item_add_subtree(ti, ett_seq[level]);
 1722                          else 
 1723                                  pt2 = pt;
 1724   
 1725                          offset = decode_asn1_sequence(tvb, offset, len, pt2, level+1); /* recurse */
 1726   
 1727                          if ( ( ! asn1_full) && (asn1_debug || ((props.flags & OUT_FLAG_dontshow) == 0)))
 1728                                  proto_item_set_len(ti, offset - boffset);
 1729                    }
 1730                break;
 1731   
 1732              default:            /* fprintf(stderr, "Other\n"); */
 1733                    if (asn1_debug) {
 1734                            ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1735                                                     textfmt_s, boffset, clsstr, constr, tagstr,
 1736                                                     tname, name, lenbuf, empty);
 1737                    } else {
 1738                            ti = proto_tree_add_text(pt, tvb, boffset, offset - boffset + len,
 1739                                                     "(%s)%s: %s bytes %s data", tname, name,
 1740                                                     lenbuf, clsstr);
 1741                    }
 1742                    proto_item_append_text(ti, " *"); /* indicate default is used */
 1743                    offset += len; /* skip value ... */
 1744                    break;
 1745            }
 1746            g_free(oname); /* XXX, memory management ? */
 1747    }
 1748    /* proto_tree_add_text(pt, tvb, offset, 1, "Marker: offset=%d", offset); */
 1749   
 1750    getPDUprops(&props, soffset, ASN1_EOI, 0, 0); /* mark end of this sequence */
 1751   
 1752    return offset;
 1753  }
Show more  




Change Warning 5558.35869 : Format String

Because they are very similar, this warning shares annotations with warning 5558.35870.

Priority:
State:
Finding:
Owner:
Note: