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

expecting time_t == unsigned long is not portable #484

Open
obache opened this issue Oct 11, 2017 · 1 comment · May be fixed by #828
Open

expecting time_t == unsigned long is not portable #484

obache opened this issue Oct 11, 2017 · 1 comment · May be fixed by #828

Comments

@obache
Copy link
Contributor

obache commented Oct 11, 2017

In some source codes, it is expected that time_t == unsigned long:

cyrus-sasl/lib/saslutil.c

Lines 283 to 286 in 1f1c3db

if (hostflag && conn->serverFQDN)
snprintf(buf,maxlen, "<%lu.%lu@%s>", randnum, now, conn->serverFQDN);
else
snprintf(buf,maxlen, "<%lu.%lu>", randnum, now);

snprintf(ret,15,"%lu",t%(0xFFFFFF));

cyrus-sasl/plugins/otp.c

Lines 648 to 649 in 1f1c3db

sprintf(data, "%s\t%04d\t%s\t%s\t%020ld",
alg, seq, seed, buf, timeout);

cyrus-sasl/plugins/otp.c

Lines 709 to 710 in 1f1c3db

sscanf(secret, "%s\t%04d\t%s\t%s\t%020ld",
alg, seq, seed, buf, timeout);

But it is not portable, for example, 32bit arch (long=32bit) with 64bit time_t platforms,
and such mis-usage in printf/scanf cause unwanted memory access, and unwanted result.

@obache
Copy link
Contributor Author

obache commented Oct 12, 2017

One more usage:

fprintf(stderr, "\"%lu\",", ref_bucket->created);

bgermann added a commit to bgermann/cyrus-sasl that referenced this issue Mar 20, 2024
In some format strings, it is expected that time_t is long.
long is 32 bit for 32 bit architectures, while time_t might be 64 bit.
Extend the format string specifiers to long long, which is guaranteed to
consist of 64 bits.

Closes: cyrusimap#484

Signed-off-by: Bastian Germann <bage@debian.org>
bgermann added a commit to bgermann/cyrus-sasl that referenced this issue Mar 20, 2024
In some format strings, it is expected that time_t is long.
long is 32 bit for 32 bit architectures, while time_t might be 64 bit.
Extend the format string specifiers to long long, which is guaranteed to
consist of 64 bits.

Closes: cyrusimap#484

Signed-off-by: Bastian Germann <bage@debian.org>
bgermann added a commit to bgermann/cyrus-sasl that referenced this issue Mar 20, 2024
In some format strings, it is expected that time_t is the same size as long.
long is 32 bit for 32 bit architectures, while time_t might be 64 bit.
Extend the format string specifiers to long long, which can hold a
time_t regardless of the platform and libc configuration.

Closes: cyrusimap#484

Signed-off-by: Bastian Germann <bage@debian.org>
@bgermann bgermann linked a pull request Mar 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant