Skip to content

Commit

Permalink
try to fix called column which was terminated with NULL instead of '\…
Browse files Browse the repository at this point in the history
…0' which was causing overflowing this value
  • Loading branch information
Martin Vit committed Feb 5, 2011
1 parent 9b60140 commit 226d630
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sniff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ char * gettag(const void *ptr, unsigned long len, const char *tag, unsigned long
int get_sip_peercnam(char *data, int data_len, char *tag, char *peername, int peername_len){
unsigned long r, r2, peername_tag_len;
char *peername_tag = gettag(data, data_len, tag, &peername_tag_len);
if(!peername_tag_len) {
goto fail_exit;
}
if ((r = (unsigned long)memmem(peername_tag, peername_tag_len, "\"", 1)) == 0){
goto fail_exit;
}
r += 1;
if ((r2 = (unsigned long)memmem(peername_tag, peername_tag_len, "\" <", 3)) == 0){
goto fail_exit;
}
if (r2 <= r){
if (r2 <= r || ((r2 - r) > peername_len) ){
goto fail_exit;
}
memcpy(peername, (void*)r, r2 - r);
memset(peername + (r2 - r), 0, 1);
peername[r2 - r] = '\0';
return 0;
fail_exit:
strcpy(peername, "empty");
Expand All @@ -118,18 +121,21 @@ int get_sip_peercnam(char *data, int data_len, char *tag, char *peername, int pe
int get_sip_peername(char *data, int data_len, char *tag, char *peername, int peername_len){
unsigned long r, r2, peername_tag_len;
char *peername_tag = gettag(data, data_len, tag, &peername_tag_len);
if(!peername_tag_len) {
goto fail_exit;
}
if ((r = (unsigned long)memmem(peername_tag, peername_tag_len, "sip:", 4)) == 0){
goto fail_exit;
}
r += 4;
if ((r2 = (unsigned long)memmem(peername_tag, peername_tag_len, "@", 1)) == 0){
goto fail_exit;
}
if (r2 <= r){
if (r2 <= r || ((r2 - r) > peername_len) ){
goto fail_exit;
}
memcpy(peername, (void*)r, r2 - r);
memset(peername + (r2 - r), 0, 1);
peername[r2 - r] = '\0';
return 0;
fail_exit:
strcpy(peername, "empty");
Expand Down

0 comments on commit 226d630

Please sign in to comment.