aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/iseries.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2008-05-29 23:30:51 +0000
committerGuy Harris <guy@alum.mit.edu>2008-05-29 23:30:51 +0000
commit9ab8f5a907713f2d4dd5fdc4c1657f78249cfcda (patch)
tree9b9c89246b49c1c6b8a0ce3768286350a59fb8a9 /wiretap/iseries.c
parentbdd6b807d7a8623c5bac942d636b8a0e3ce0f19a (diff)
Have iseries_parse_hex_string() take a "const char *" as its first
argument, as 1) it doesn't modify the string that argument points to and 2) it's a buffer of "char". Use g_ascii_xdigit_value() and put the values of the two bytes together ourselves; strtoul() is a bit of overkill for two-hex-digit pairs. While we're at it, check for invalid hex digits, and for bytes where only one hex digit is present. svn path=/trunk/; revision=25392
Diffstat (limited to 'wiretap/iseries.c')
-rw-r--r--wiretap/iseries.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/wiretap/iseries.c b/wiretap/iseries.c
index ed66f54f4c..4c31cf1724 100644
--- a/wiretap/iseries.c
+++ b/wiretap/iseries.c
@@ -148,7 +148,7 @@ static int iseries_parse_packet (wtap * wth, FILE_T fh,
union wtap_pseudo_header *pseudo_header,
guint8 * pd, int *err, gchar ** err_info);
static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes);
-static gboolean iseries_parse_hex_string (guint8 * ascii, guint8 * buf,
+static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf,
int len);
int
@@ -817,18 +817,31 @@ iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes)
* Requires ASCII hex data and buffer to populate with binary data
*/
static gboolean
-iseries_parse_hex_string (guint8 * ascii, guint8 * buf, int len)
+iseries_parse_hex_string (const char * ascii, guint8 * buf, int len)
{
int i, byte;
- char hexvalue[3] = { 0, 0, 0 };
+ gint hexvalue;
+ guint8 bytevalue;
byte = 0;
- for (i = 0; i < len; i++)
+ i = 0;
+ for (;;)
{
- hexvalue[0] = ascii[i];
+ if (i >= len)
+ break;
+ hexvalue = g_ascii_xdigit_value(ascii[i]);
i++;
- hexvalue[1] = ascii[i];
- buf[byte] = (guint8) strtoul (hexvalue, NULL, 16);
+ if (hexvalue == -1)
+ return FALSE; /* not a valid hex digit */
+ bytevalue = (guint8)(hexvalue << 4);
+ if (i >= len)
+ return FALSE; /* only one hex digit of the byte is present */
+ hexvalue = g_ascii_xdigit_value(ascii[i]);
+ i++;
+ if (hexvalue == -1)
+ return FALSE; /* not a valid hex digit */
+ bytevalue |= (guint8) hexvalue;
+ buf[byte] = bytevalue;
byte++;
}
return TRUE;