A
auto.ptr
option[0].....option[312]......
|--> p?
|--> p?
assert( (p+len) <= end); // include <assert.h>, you could alsoRoman said:Hello, All!
In this piece of code I get 'segmentation fault' periodically: [...]
do {
len = *(++p); /* save option length */
p--; len = *p;
if ( *p == 190 || *p == 191 ) {
opt = *p;
p += 2;
}strncpy(tmp, (char *)p, len);
printf("option %u found, value is %s\n", opt, tmp);
p += len;
------------^}
else
p = (p + 2) + len; /* move pointer to the next tag */
} while ( p != end );
Le 15-11-2005 said:struct dhcp_hdr {
/* ... various fields here*/
unsigned char options[312];
}
...
struct dhcp_hdr *dhcph;
unsigned char *p, *end, opt;
char *tmp = NULL;
unsigned int len=0;
...
p = dhcph->options + 4;
end = dhcph->options + sizeof(dhcph->options);
tmp = malloc(100);
do {
len = *(++p); /* save option length */
p--;
if ( *p == 190 || *p == 191 ) {
opt = *p;
p += 2;
strncpy(tmp, (char *)p, len);
printf("option %u found, value is %s\n", opt, tmp);
p += len;
}
else
p = (p + 2) + len; /* move pointer to the next tag */
} while ( p != end );
...
Seems like 'p' points to illegal chunk of memory at some time and I'm unable
to find this properly. Where can it be?
Roman said:Hello, All!
In this piece of code I get 'segmentation fault' periodically:
struct dhcp_hdr {
/* ... various fields here*/
unsigned char options[312];
}
struct dhcp_hdr *dhcph;
unsigned char *p, *end, opt;
char *tmp = NULL;
unsigned int len=0;
...
p = dhcph->options + 4;
end = dhcph->options + sizeof(dhcph->options);
tmp = malloc(100);
do {
len = *(++p);
p--;
if ( *p == 190 || *p == 191 ) {
opt = *p;
p += 2;
strncpy(tmp, (char *)p, len);
printf("option %u found, value is %s\n", opt, tmp);
p += len;
}
else
p = (p + 2) + len; /* move pointer to the next tag */
} while ( p != end );
Roman said:In this piece of code I get 'segmentation fault' periodically:
...
struct dhcp_hdr {
/* ... various fields here*/
unsigned char options[312];
}
...
struct dhcp_hdr *dhcph;
unsigned char *p, *end, opt;
char *tmp = NULL;
unsigned int len=0;
...
p = dhcph->options + 4;
end = dhcph->options + sizeof(dhcph->options);
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.