-
Notifications
You must be signed in to change notification settings - Fork 242
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
Remove strtou[l]l_noneg(), replacing them by a2i() calls #895
Merged
alejandro-colomar
merged 4 commits into
shadow-maint:master
from
alejandro-colomar:rm_noneg
May 27, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9bb6397
lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
alejandro-colomar 19cc0df
lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused f…
alejandro-colomar e189b6e
src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
alejandro-colomar 15af2f3
lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused fu…
alejandro-colomar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2017, Chris Lamb | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
// SPDX-FileCopyrightText: 2017, Chris Lamb | ||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <[email protected]> | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
||
#include <config.h> | ||
|
||
|
@@ -12,58 +11,37 @@ | |
#include <limits.h> | ||
#include <stdio.h> | ||
|
||
#include "atoi/strtou_noneg.h" | ||
#include "atoi/a2i.h" | ||
#include "defines.h" | ||
#include "prototypes.h" | ||
#include "shadowlog.h" | ||
|
||
|
||
/* | ||
* gettime() returns the time as the number of seconds since the Epoch | ||
* | ||
* Like time(), gettime() returns the time as the number of seconds since the | ||
* Epoch, 1970-01-01 00:00:00 +0000 (UTC), except that if the SOURCE_DATE_EPOCH | ||
* environment variable is exported it will use that instead. | ||
*/ | ||
/*@observer@*/time_t gettime (void) | ||
/*@observer@*/time_t | ||
gettime(void) | ||
{ | ||
char *end; | ||
char *source_date_epoch; | ||
time_t fallback; | ||
unsigned long long epoch; | ||
FILE *shadow_logfd = log_get_logfd(); | ||
char *source_date_epoch; | ||
FILE *shadow_logfd = log_get_logfd(); | ||
time_t fallback, epoch; | ||
|
||
fallback = time (NULL); | ||
source_date_epoch = shadow_getenv ("SOURCE_DATE_EPOCH"); | ||
|
||
if (!source_date_epoch) | ||
return fallback; | ||
|
||
errno = 0; | ||
epoch = strtoull_noneg(source_date_epoch, &end, 10); | ||
if (errno != 0) { | ||
fprintf (shadow_logfd, | ||
_("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"), | ||
strerror(errno)); | ||
} else if (end == source_date_epoch) { | ||
fprintf (shadow_logfd, | ||
_("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"), | ||
end); | ||
} else if (*end != '\0') { | ||
fprintf (shadow_logfd, | ||
_("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"), | ||
end); | ||
} else if (epoch > ULONG_MAX) { | ||
fprintf (shadow_logfd, | ||
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"), | ||
ULONG_MAX, epoch); | ||
} else if ((time_t)epoch > fallback) { | ||
fprintf (shadow_logfd, | ||
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to the current time (%lu) but was found to be: %llu\n"), | ||
fallback, epoch); | ||
} else { | ||
/* Valid */ | ||
return epoch; | ||
if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) { | ||
fprintf(shadow_logfd, | ||
ikerexxe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_("Environment variable $SOURCE_DATE_EPOCH: a2i(\"%s\"): %s"), | ||
source_date_epoch, strerror(errno)); | ||
return fallback; | ||
} | ||
|
||
return fallback; | ||
return epoch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@lamby Should we accept negative values? Why did this use strtoull(1) originally?
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.
I'm blocked until this questions is answered. Feel free to close it and merge the PR at your convenience
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.
Thanks! I'm merging.