Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs caused by strtok_r #783

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/cidr.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ parse_cidr(tcpr_cidr_t ** cidrdata, char *cidrin, char *delim)

/* first iteration of input using strtok */
network = strtok_r(cidrin, delim, &token);
if (network == NULL)
return 0;

*cidrdata = cidr2cidr(network);
cidr_ptr = *cidrdata;
Expand Down Expand Up @@ -362,6 +364,8 @@ parse_endpoints(tcpr_cidrmap_t ** cidrmap1, tcpr_cidrmap_t ** cidrmap2, const ch
/* ipv4 mode */
memset(newmap, '\0', NEWMAP_LEN);
map = strtok_r(string, ":", &token);
if (map == NULL)
goto done;

strlcpy(newmap, "0.0.0.0/0:", NEWMAP_LEN);
strlcat(newmap, map, NEWMAP_LEN);
Expand Down
2 changes: 1 addition & 1 deletion src/common/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ parse_list(tcpr_list_t ** listdata, char *ourstr)
second = NULL;

/* regex test */
if (regexec(&preg, this, 0, NULL, 0) != 0) {
if (this == NULL || regexec(&preg, this, 0, NULL, 0) != 0) {
warnx("Unable to parse: %s", this);
regfree(&preg);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/common/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ macinstring(const char *macstring, const u_char *mac)
memset(&tempmac[0], 0, sizeof(tempmac));

tempstr = strtok_r(ourstring, ",", &tok);
if (strlen(tempstr)) {
if (tempstr != NULL && strlen(tempstr)) {
mac2hex(tempstr, tempmac, len);
if (memcmp(mac, tempmac, len) == 0) {
dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac));
Expand Down
2 changes: 2 additions & 0 deletions src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ read_hexstring(const char *l2string, u_char *hex, const int hexlen)

/* get the first byte */
l2byte = strtok_r(string, ",", &token);
if (l2byte == NULL)
err(-1, "Hex buffer must contain something");
sscanf(l2byte, "%x", &value);
if (value > 0xff)
errx(-1, "Invalid hex string byte: %s", l2byte);
Expand Down
2 changes: 1 addition & 1 deletion src/tcpedit/portmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ parse_portmap(tcpedit_portmap_t ** portmap, const char *ourstr)
/* first iteration of input */
substr = strtok_r(ourstrcpy, ",", &token);

if ((*portmap = ports2PORT(substr)) == NULL) {
if (substr == NULL || (*portmap = ports2PORT(substr)) == NULL) {
safe_free(ourstrcpy);
return 0;
}
Expand Down