Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at catapult_dct2000.c:849

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

parse_line

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/catapult_dct2000.c)expand/collapse
Show more  
 826  gboolean parse_line(gint line_length, gint *seconds, gint *useconds,
 827                      long *before_time_offset, long *after_time_offset,
 828                      long *data_offset, gint *data_chars,
 829                      packet_direction_t *direction,
 830                      int *encap)
 831  {
 832      int  n = 0;
 833      int  port_digits = 0;
 834      char port_number_string[MAX_PORT_DIGITS+1];
 835      int  variant_digits = 0;
 836      int  variant = 1;
 837      int  protocol_chars = 0;
 838      int  outhdr_chars = 0;
 839   
 840      char seconds_buff[MAX_SECONDS_CHARS+1];
 841      int  seconds_chars;
 842      char subsecond_decimals_buff[MAX_SUBSECOND_DECIMALS+1];
 843      int  subsecond_decimals_chars;
 844      int  skip_first_byte = FALSE;
 845   
 846      gboolean atm_header_present = FALSE;
 847   
 848      /* Read context name until find '.' */
 849      for (n=0; linebuff[n] != '.' && (n < MAX_CONTEXT_NAME) && (n+1 < line_length); n++)
 850      {
 851          if (!isalnum((guchar)linebuff[n]) && (linebuff[n] != '_') && (linebuff[n] != '-'))
 852          {
 853              return FALSE;
 854          }
 855          context_name[n] = linebuff[n];
 856      }
 857      if (n == MAX_CONTEXT_NAME || (n+1 >= line_length))
 858      {
 859          return FALSE;
 860      }
 861   
 862      /* '.' must follow context name */
 863      if (linebuff[n] != '.')
 864      {
 865          return FALSE;
 866      }
 867      context_name[n] = '\0';
 868      /* Skip it */
 869      n++;
 870   
 871   
 872      /* Now read port number */
 873      for (port_digits = 0;
 874           (linebuff[n] != '/') && (port_digits <= MAX_PORT_DIGITS) && (n+1 < line_length);
 875           n++, port_digits++)
 876      {
 877          if (!isdigit((guchar)linebuff[n]))
 878          {
 879              return FALSE;
 880          }
 881          port_number_string[port_digits] = linebuff[n];
 882      }
 883      if (port_digits > MAX_PORT_DIGITS || (n+1 >= line_length))
 884      {
 885          return FALSE;
 886      }
 887   
 888      /* Slash char must follow port number */
 889      if (linebuff[n] != '/')
 890      {
 891          return FALSE;
 892      }
 893      port_number_string[port_digits] = '\0';
 894      context_port = atoi(port_number_string);
 895      /* Skip it */
 896      n++;
 897   
 898   
 899      /* Now for the protocol name */
 900      for (protocol_chars = 0;
 901           (linebuff[n] != '/') && (protocol_chars < MAX_PROTOCOL_NAME) && (n < line_length);
 902           n++, protocol_chars++)
 903      {
 904          if (!isalnum((guchar)linebuff[n]) && linebuff[n] != '_')
 905          {
 906              return FALSE;
 907          }
 908          protocol_name[protocol_chars] = linebuff[n];
 909      }
 910      if (protocol_chars == MAX_PROTOCOL_NAME || n >= line_length)
 911      {
 912          /* If doesn't fit, fail rather than truncate */
 913          return FALSE;
 914      }
 915      protocol_name[protocol_chars] = '\0';
 916   
 917      /* Slash char must follow protocol name */
 918      if (linebuff[n] != '/')
 919      {
 920          return FALSE;
 921      }
 922      /* Skip it */
 923      n++;
 924   
 925   
 926      /* Following the / is the variant number.  No digits indicate 1 */
 927      for (variant_digits = 0;
 928           (isdigit((guchar)linebuff[n])) && (variant_digits <= MAX_VARIANT_DIGITS) && (n+1 < line_length);
 929           n++, variant_digits++)
 930      {
 931          if (!isdigit((guchar)linebuff[n]))
 932          {
 933              return FALSE;
 934          }
 935          variant_name[variant_digits] = linebuff[n];
 936      }
 937      if (variant_digits > MAX_VARIANT_DIGITS || (n+1 >= line_length))
 938      {
 939          return FALSE;
 940      }
 941      if (variant_digits > 0)
 942      {
 943          variant_name[variant_digits] = '\0';
 944          variant = atoi(variant_name);
 945      }
 946      else 
 947      {
 948          g_strlcpy(variant_name, "1", MAX_VARIANT_DIGITS+1);
 949      }
 950   
 951   
 952      /* Outheader values may follow */
 953      outhdr_name[0] = '\0';
 954      if (linebuff[n] == ',')
 955      {
 956          /* Skip , */
 957          n++;
 958   
 959          for (outhdr_chars = 0;
 960               (isdigit((guchar)linebuff[n]) || linebuff[n] == ',') &&
 961               (outhdr_chars <= MAX_OUTHDR_NAME) && (n+1 < line_length);
 962               n++, outhdr_chars++)
 963          {
 964              if (!isdigit((guchar)linebuff[n]) && (linebuff[n] != ','))
 965              {
 966                  return FALSE;
 967              }
 968              outhdr_name[outhdr_chars] = linebuff[n];
 969          }
 970          if (outhdr_chars > MAX_OUTHDR_NAME || (n+1 >= line_length))
 971          {
 972              return FALSE;
 973          }
 974          /* Terminate (possibly empty) string */
 975          outhdr_name[outhdr_chars] = '\0';
 976      }
 977   
 978   
 979   
 980   
 981      /******************************************************************/
 982      /* Now check whether we know how to use a packet of this protocol */
 983   
 984      if ((strcmp(protocol_name, "ip") == 0) ||
 985          (strcmp(protocol_name, "sctp") == 0) ||
 986          (strcmp(protocol_name, "gre") == 0) ||
 987          (strcmp(protocol_name, "mipv6") == 0) ||
 988          (strcmp(protocol_name, "igmp") == 0))
 989      {
 990          *encap = WTAP_ENCAP_RAW_IP;
 991      }
 992      else 
 993   
 994      /* FP may be carried over ATM, which has separate atm header to parse */
 995      if ((strcmp(protocol_name, "fp") == 0) ||
 996          (strcmp(protocol_name, "fp_r4") == 0) ||
 997          (strcmp(protocol_name, "fp_r5") == 0) ||
 998          (strcmp(protocol_name, "fp_r6") == 0) ||
 999          (strcmp(protocol_name, "fp_r7") == 0))
 1000      {
 1001          if ((variant > 256) && (variant % 256 == 3))
 1002          {
 1003              /* FP over udp is contained in IPPrim... */
 1004              *encap = 0;
 1005          }
 1006          else 
 1007          {
 1008              /* FP over AAL0 or AAL2 */
 1009              *encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED;
 1010              atm_header_present = TRUE;
 1011          }
 1012      }
 1013      else if (strcmp(protocol_name, "fpiur_r5") == 0)
 1014      {
 1015          /* FP (IuR) over AAL2 */
 1016          *encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED;
 1017          atm_header_present = TRUE;
 1018      }
 1019   
 1020   
 1021      else 
 1022      if (strcmp(protocol_name, "ppp") == 0)
 1023      {
 1024          *encap = WTAP_ENCAP_PPP;
 1025      }
 1026      else 
 1027      if (strcmp(protocol_name, "isdn_l3") == 0)
 1028      {
 1029         /* TODO: find out what this byte means... */
 1030          skip_first_byte = TRUE;
 1031          *encap = WTAP_ENCAP_ISDN;
 1032      }
 1033      else 
 1034      if (strcmp(protocol_name, "isdn_l2") == 0)
 1035      {
 1036          *encap = WTAP_ENCAP_ISDN;
 1037      }
 1038      else 
 1039      if (strcmp(protocol_name, "ethernet") == 0)
 1040      {
 1041          *encap = WTAP_ENCAP_ETHERNET;
 1042      }
 1043      else 
 1044      if ((strcmp(protocol_name, "saalnni_sscop") == 0) ||
 1045          (strcmp(protocol_name, "saaluni_sscop") == 0))
 1046      {
 1047          *encap = DCT2000_ENCAP_SSCOP;
 1048      }
 1049      else 
 1050      if (strcmp(protocol_name, "frelay_l2") == 0)
 1051      {
 1052          *encap = WTAP_ENCAP_FRELAY;
 1053      }
 1054      else 
 1055      if (strcmp(protocol_name, "ss7_mtp2") == 0)
 1056      {
 1057          *encap = DCT2000_ENCAP_MTP2;
 1058      }
 1059      else 
 1060      if ((strcmp(protocol_name, "nbap") == 0) ||
 1061          (strcmp(protocol_name, "nbap_r4") == 0) ||
 1062          (strncmp(protocol_name, "nbap_sscfuni", strlen("nbap_sscfuni")) == 0))
 1063      {
 1064          /* The entire message in these cases is nbap, so use an encap value. */
 1065          *encap = DCT2000_ENCAP_NBAP;
 1066      }
 1067      else 
 1068      {
 1069          /* Not a supported board port protocol/encap, but can show as raw data or 
 1070             in some cases find protocol embedded inside primitive */
 1071          *encap = DCT2000_ENCAP_UNHANDLED;
 1072      }
 1073   
 1074   
 1075      /* Find separate ATM header if necessary */
 1076      if (atm_header_present)
 1077      {
 1078          int header_chars_seen = 0;
 1079   
 1080          /* Scan ahead to the next $ */
 1081          for (; (linebuff[n] != '$') && (n+1 < line_length); n++);
 1082          /* Skip it */
 1083          n++;
 1084          if (n+1 >= line_length)
 1085          {
 1086              return FALSE;
 1087          }
 1088   
 1089          /* Read consecutive hex chars into atm header buffer */
 1090          for (;
 1091               ((linebuff[n] >= '0') && (linebuff[n] <= '?') &&
 1092                (n < line_length) &&
 1093                (header_chars_seen < AAL_HEADER_CHARS));
 1094               n++, header_chars_seen++)
 1095          {
 1096              aal_header_chars[header_chars_seen] = linebuff[n];
 1097              /* Next 6 characters after '9' are mapped to a->f */
 1098              if (!isdigit((guchar)linebuff[n]))
 1099              {
 1100                  aal_header_chars[header_chars_seen] = 'a' + (linebuff[n] - '9') -1;
 1101              }
 1102          }
 1103   
 1104          if (header_chars_seen != AAL_HEADER_CHARS || n >= line_length)
 1105          {
 1106              return FALSE;
 1107          }
 1108      }
 1109   
 1110   
 1111      /* Scan ahead to the next space */
 1112      for (; (linebuff[n] != ' ') && (n+1 < line_length); n++);
 1113      if (n+1 >= line_length)
 1114      {
 1115          return FALSE;
 1116      }
 1117      /* Skip it */
 1118      n++;
 1119   
 1120      /* Next character gives direction of message (must be 's' or 'r') */
 1121      if (linebuff[n] == 's')
 1122      {
 1123          *direction = sent;
 1124      }
 1125      else 
 1126      if (linebuff[n] == 'r')
 1127      {
 1128          *direction = received;
 1129      }
 1130      else 
 1131      {
 1132          return FALSE;
 1133      }
 1134      /* Skip it */
 1135      n++;
 1136   
 1137   
 1138      /*********************************************************************/
 1139      /* Find and read the timestamp                                       */
 1140   
 1141      /* Now scan to the next digit, which should be the start of the timestamp */
 1142      /* This will involve skipping " tm "                                      */
 1143      for (; !isdigit((guchar)linebuff[n]) && (n < line_length); n++);
 1144      if (n >= line_length)
 1145      {
 1146          return FALSE;
 1147      }
 1148   
 1149      *before_time_offset = n;
 1150   
 1151      /* Seconds */
 1152      for (seconds_chars = 0;
 1153           (linebuff[n] != '.') &&
 1154           (seconds_chars <= MAX_SECONDS_CHARS) &&
 1155           (n < line_length);
 1156           n++, seconds_chars++)
 1157      {
 1158          if (!isdigit((guchar)linebuff[n]))
 1159          {
 1160              /* Found a non-digit before decimal point. Fail */
 1161              return FALSE;
 1162          }
 1163          seconds_buff[seconds_chars] = linebuff[n];
 1164      }
 1165      if (seconds_chars > MAX_SECONDS_CHARS || n >= line_length)
 1166      {
 1167          /* Didn't fit in buffer.  Fail rather than use truncated */
 1168          return FALSE;
 1169      }
 1170   
 1171      /* Convert found value into number */
 1172      seconds_buff[seconds_chars] = '\0';
 1173      *seconds = atoi(seconds_buff);
 1174   
 1175      /* The decimal point must follow the last of the seconds digits */
 1176      if (linebuff[n] != '.')
 1177      {
 1178          return FALSE;
 1179      }
 1180      /* Skip it */
 1181      n++;
 1182   
 1183      /* Subsecond decimal digits (expect 4-digit accuracy) */
 1184      for (subsecond_decimals_chars = 0;
 1185           (linebuff[n] != ' ') &&
 1186           (subsecond_decimals_chars <= MAX_SUBSECOND_DECIMALS) &&
 1187           (n < line_length);
 1188           n++, subsecond_decimals_chars++)
 1189      {
 1190          if (!isdigit((guchar)linebuff[n]))
 1191          {
 1192              return FALSE;
 1193          }
 1194          subsecond_decimals_buff[subsecond_decimals_chars] = linebuff[n];
 1195      }
 1196      if (subsecond_decimals_chars > MAX_SUBSECOND_DECIMALS || n >= line_length)
 1197      {
 1198          /* More numbers than expected - give up */
 1199          return FALSE;
 1200      }
 1201      /* Convert found value into microseconds */
 1202      subsecond_decimals_buff[subsecond_decimals_chars] = '\0';
 1203      *useconds = atoi(subsecond_decimals_buff) * 100;
 1204   
 1205      /* Space character must follow end of timestamp */
 1206      if (linebuff[n] != ' ')
 1207      {
 1208          return FALSE;
 1209      }
 1210   
 1211      *after_time_offset = n;
 1212   
 1213      /* Now skip ahead to find start of data (marked by '$') */
 1214      for (; (linebuff[n] != '$') && (n+1 < line_length); n++);
 1215      if (n+1 >= line_length)
 1216      {
 1217          return FALSE;
 1218      }
 1219      /* Skip it */
 1220      n++;
 1221   
 1222      /* Set offset to data start within line */
 1223      *data_offset = n;
 1224   
 1225      /* Set number of chars that comprise the hex string protocol data */
 1226      *data_chars = line_length - n;
 1227   
 1228      /* May need to skip first byte (2 hex string chars) */
 1229      if (skip_first_byte)
 1230      {
 1231          *data_offset += 2;
 1232          *data_chars -= 2;
 1233      }
 1234   
 1235   
 1236      return TRUE;
 1237  }
Show more  




Change Warning 967.29804 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: