-
Notifications
You must be signed in to change notification settings - Fork 274
librc/run/shutdown: precalc strlen moved out of bounds loop #790
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -308,6 +308,9 @@ write_prefix(const char *buffer, size_t bytes, bool *prefixed) | |
| else | ||
| ewarnv("Couldn't open the prefix lock, please make sure you have enough permissions"); | ||
|
|
||
| size_t len_ec = strlen(ec); | ||
| size_t len_prefix = strlen(prefix); | ||
| size_t len_ec_normal = strlen(ec_normal); | ||
| for (i = 0; i < bytes; i++) { | ||
| /* We don't prefix eend calls (cursor up) */ | ||
| if (buffer[i] == '\033' && !*prefixed) { | ||
|
|
@@ -320,9 +323,9 @@ write_prefix(const char *buffer, size_t bytes, bool *prefixed) | |
| } | ||
|
|
||
| if (!*prefixed) { | ||
|
Member
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. this codepath is called once per-line. while calling this function with multiline strings is certainly valid, and i'm sure done in places, it's not the common case, and I have a hard time seeing strlen being called on tiny strings showing up in any perf situation. len_ec & ec_normal will be like 7 bytes each. len_prefix will be ~length of longest service name, and that's likely to also be quite small. |
||
| ret += write(fd, ec, strlen(ec)); | ||
| ret += write(fd, prefix, strlen(prefix)); | ||
| ret += write(fd, ec_normal, strlen(ec_normal)); | ||
| ret += write(fd, ec, len_ec); | ||
| ret += write(fd, prefix, len_prefix); | ||
| ret += write(fd, ec_normal, len_ec_normal); | ||
| ret += write(fd, "|", 1); | ||
| *prefixed = true; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,10 +144,11 @@ void broadcast(char *text) | |
|
|
||
| setutxent(); | ||
|
|
||
| size_t len_path_dev = strlen(_PATH_DEV); | ||
| while ((utmp = getutxent()) != NULL) { | ||
| if (utmp->ut_type != USER_PROCESS || utmp->ut_user[0] == 0) | ||
| continue; | ||
| if (strncmp(utmp->ut_line, _PATH_DEV, strlen(_PATH_DEV)) == 0) | ||
|
Member
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.
|
||
| if (strncmp(utmp->ut_line, _PATH_DEV, len_path_dev) == 0) | ||
| xasprintf(&term, "%s", utmp->ut_line); | ||
| else | ||
| xasprintf(&term, "%s%s", _PATH_DEV, utmp->ut_line); | ||
|
|
||
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.
these strlen calls simply want to know if the string is empty. that can be checked by
my_ns[0]andproc_ns[0]-- no need for strlen at all.