-
Notifications
You must be signed in to change notification settings - Fork 49
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
Unnecessary string truncation in src/scrot.c #223
Comments
we cannot use HOST_NAME_MAX because it's not defined by macos and freebsd. instead use sysconf and reserve enough for hostNameMax, so that we can call gethostname directly on the return buffer avoiding unncessary copy and allocation. ref: resurrecting-open-source-projects#223
we cannot use HOST_NAME_MAX because it's not defined by macos and freebsd. instead use sysconf and reserve enough for hostNameMax, so that we can call gethostname directly on the return buffer avoiding unncessary copy and allocation. ref: resurrecting-open-source-projects#223
we cannot use HOST_NAME_MAX because it's not defined by macos and freebsd. instead use sysconf and reserve enough for hostNameMax, so that we can call gethostname directly on the return buffer avoiding unncessary copy and allocation. ref: resurrecting-open-source-projects#223
we cannot use HOST_NAME_MAX because it's not defined by macos and freebsd. instead use sysconf and reserve enough for hostNameMax, so that we can call gethostname directly on the return buffer avoiding unncessary copy and allocation. ref: resurrecting-open-source-projects#223
we cannot use HOST_NAME_MAX because it's not defined by macos and freebsd. instead use sysconf and reserve enough for hostNameMax, so that we can call gethostname directly on the return buffer avoiding unncessary copy and allocation. ref: #223
Github doesn't understand "partially fixes" and keeps closing this, pretty annoying. :/ But in any case, |
I think the only remaining issue now is the Stream ret = {0};
long hostNameMax = 0;
- char strf[4096];
+ char *strf = NULL;
+ size_t strfSize = 64;
char *tmp;
struct stat st;
- if (strftime(strf, 4095, str, tm) == 0)
- errx(EXIT_FAILURE, "strftime returned 0");
+ do {
+ strfSize *= 2;
+ strf = erealloc(strf, strfSize);
+ } while (strftime(strf, strfSize, str, tm) == 0); /* FIXME: infinite loop */
imlib_context_set_image(im); But the problem is strftime can validly return 0 and there's no way to distinguish between a valid 0 return vs a 0 return due to small buffer. |
Filenames can't be the null string, I've been reading books instead of contributing as of late. |
From the
So if someone does
It's voluntary work, do it at your own pace :) |
Maybe we can use |
In the case of error 0 return, the contents of
So we can't read the contents of the buffer to make any conclusions.
I'll take a look into it. |
POSIX says unspecified. It's unlikely an an implementation wouldn't output directly to the buffer anyway. |
If the output file is an absolute path (starts with |
this avoids unnecessary limit on the filename length (at the cost of creating new failure points due to dynamic allocations). the biggest annoyance, and the reason why an additional dynamically allocated buffer was necessary, is the fact that strftime() doesn't have a way to distinguish between valid 0 return vs 0 return due to small buffer. prepending a useless '.' in the format buffer and skipping over it later on solves this issue since it can no longer "validly" return 0. Fixes: resurrecting-open-source-projects#223
this avoids unnecessary limit on the filename length (at the cost of creating new failure points due to dynamic allocations). the biggest annoyance, and the reason why an additional dynamically allocated buffer was necessary, is the fact that strftime() doesn't have a way to distinguish between valid 0 return vs 0 return due to small buffer. prepending a useless '.' in the format buffer and skipping over it later on solves this issue since it can no longer "validly" return 0. Fixes: #223
This truncates:
scrot/src/scrot.c
Lines 613 to 614 in 4c59bd4
sizeof(buf) is 20:
scrot/src/scrot.c
Line 596 in 4c59bd4
POSIX says:
Further down:
The fix here is to make buf's size HOST_NAME_MAX+1, but the real problem is the function's design. It should make gethostname() directly output to ret and it should dynamically grow ret as needed.
The text was updated successfully, but these errors were encountered: