Skip to content

Commit

Permalink
Fix a bug in my IP handling. (#118)
Browse files Browse the repository at this point in the history
* Fix a bug in my IP handling.

* Improve error message.
  • Loading branch information
manugarg committed Mar 23, 2022
1 parent 7bce167 commit 943231b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/pacparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,17 @@ static JSClass global_class = {
};

// Set my (client's) IP address to a custom value.
void
int
pacparser_setmyip(const char *ip)
{
if (strlen(ip) > INET6_ADDRSTRLEN) {
fprintf(stderr, "pacparser_setmyip: IP too long: %s\n", ip);
return 0;
}

myip = malloc(strlen(ip) +1); // Allocate space just to be sure.
strcpy(myip, ip);
return 1;
}

// Decprecated: This function doesn't do anything.
Expand Down
3 changes: 2 additions & 1 deletion src/pacparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ void pacparser_cleanup(void);

/// @brief Sets my IP address.
/// @param ip Custom IP address.
/// @returns 1 on success and 0 on error.
///
/// Sets my IP address to a custom value. This is the IP address returned by
/// myIpAddress() javascript function.
void pacparser_setmyip(const char *ip // Custom IP address.
int pacparser_setmyip(const char *ip // Custom IP address.
);

/// @brief Type definition for pacparser_error_printer.
Expand Down
6 changes: 5 additions & 1 deletion src/pactester.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ int main(int argc, char* argv[])
}

if (client_ip)
pacparser_setmyip(client_ip);
if (!pacparser_setmyip(client_ip)) {
fprintf(stderr, "pactester.c: Error setting client IP\n");
pacparser_cleanup();
return 1;
}

char *proxy;

Expand Down

0 comments on commit 943231b

Please sign in to comment.