-
Notifications
You must be signed in to change notification settings - Fork 2k
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
net/sock_util: Accept NULL pointers in urlsplit #11677
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ | |||||
#include <stdio.h> | ||||||
#include <stdlib.h> | ||||||
#include <string.h> | ||||||
#include <assert.h> | ||||||
|
||||||
#include "net/sock/udp.h" | ||||||
#include "net/sock/util.h" | ||||||
|
@@ -116,30 +117,33 @@ static char* _find_pathstart(const char *url) | |||||
|
||||||
int sock_urlsplit(const char *url, char *hostport, char *urlpath) | ||||||
{ | ||||||
assert(url); | ||||||
char *hoststart = _find_hoststart(url); | ||||||
if (!hoststart) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as you changed the others this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed back to original style |
||||||
return -EINVAL; | ||||||
} | ||||||
|
||||||
char *pathstart = _find_pathstart(hoststart); | ||||||
|
||||||
size_t hostlen = pathstart - hoststart; | ||||||
/* hostlen must be smaller SOCK_HOSTPORT_MAXLEN to have space for the null | ||||||
* terminator */ | ||||||
if (hostlen > SOCK_HOSTPORT_MAXLEN - 1) { | ||||||
return -EOVERFLOW; | ||||||
if (hostport) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
size_t hostlen = pathstart - hoststart; | ||||||
/* hostlen must be smaller SOCK_HOSTPORT_MAXLEN to have space for the null | ||||||
* terminator */ | ||||||
if (hostlen > SOCK_HOSTPORT_MAXLEN - 1) { | ||||||
return -EOVERFLOW; | ||||||
} | ||||||
memcpy(hostport, hoststart, hostlen); | ||||||
hostport[hostlen] = '\0'; | ||||||
} | ||||||
memcpy(hostport, hoststart, hostlen); | ||||||
*(hostport + hostlen) = '\0'; | ||||||
|
||||||
size_t pathlen = strlen(pathstart); | ||||||
if (pathlen) { | ||||||
if (urlpath) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
size_t pathlen = strlen(pathstart); | ||||||
if (pathlen > SOCK_URLPATH_MAXLEN - 1) { | ||||||
return -EOVERFLOW; | ||||||
} | ||||||
memcpy(urlpath, pathstart, pathlen); | ||||||
urlpath[pathlen] = '\0'; | ||||||
} | ||||||
*(urlpath + pathlen) = '\0'; | ||||||
return 0; | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the original authors style where it doesn't go against coding conventions.