Avoid using %zu or %zd with printf() and fprintf().
This prevents problems on systems where the system printf(3) is not C99-compliant. We use our own snprintf() on such systems so that is safe.
This commit is contained in:
@@ -47,7 +47,7 @@ main(int argc, char *argv[])
|
|||||||
int ch, lineno = 0, which = 0;
|
int ch, lineno = 0, which = 0;
|
||||||
char *line, lines[2][2048];
|
char *line, lines[2][2048];
|
||||||
const char *infile;
|
const char *infile;
|
||||||
size_t len;
|
unsigned int len;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
initprogname(argc > 0 ? argv[0] : "check_wrap");
|
initprogname(argc > 0 ? argv[0] : "check_wrap");
|
||||||
@@ -83,35 +83,35 @@ main(int argc, char *argv[])
|
|||||||
while ((line = fgets(lines[which], sizeof(lines[which]), fp)) != NULL) {
|
while ((line = fgets(lines[which], sizeof(lines[which]), fp)) != NULL) {
|
||||||
char *cp, *last;
|
char *cp, *last;
|
||||||
|
|
||||||
len = strcspn(line, "\n");
|
line[strcspn(line, "\n")] = '\0';
|
||||||
line[len] = '\0';
|
|
||||||
|
|
||||||
/* If we read the 2nd line, parse list of line lengths and check. */
|
/* If we read the 2nd line, parse list of line lengths and check. */
|
||||||
if (which) {
|
if (which) {
|
||||||
lineno++;
|
lineno++;
|
||||||
for (cp = strtok_r(lines[1], ",", &last); cp != NULL; cp = strtok_r(NULL, ",", &last)) {
|
for (cp = strtok_r(lines[1], ",", &last); cp != NULL; cp = strtok_r(NULL, ",", &last)) {
|
||||||
|
unsigned int maxlen;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *dash;
|
char *dash;
|
||||||
size_t maxlen;
|
|
||||||
|
|
||||||
/* May be either a number or a range. */
|
/* May be either a number or a range. */
|
||||||
dash = strchr(cp, '-');
|
dash = strchr(cp, '-');
|
||||||
if (dash != NULL) {
|
if (dash != NULL) {
|
||||||
*dash = '\0';
|
*dash = '\0';
|
||||||
len = (size_t)sudo_strtonum(cp, 0, INT_MAX, &errstr);
|
len = (unsigned int)sudo_strtonum(cp, 0, INT_MAX, &errstr);
|
||||||
if (errstr == NULL)
|
if (errstr == NULL)
|
||||||
maxlen = (size_t)sudo_strtonum(dash + 1, 0, INT_MAX, &errstr);
|
maxlen = (unsigned int)sudo_strtonum(dash + 1, 0, INT_MAX, &errstr);
|
||||||
} else {
|
} else {
|
||||||
len = maxlen = (size_t)sudo_strtonum(cp, 0, INT_MAX, &errstr);
|
len = maxlen = (unsigned int)sudo_strtonum(cp, 0, INT_MAX, &errstr);
|
||||||
}
|
}
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
sudo_fatalx("%s: invalid length on line %d", infile, lineno);
|
sudo_fatalx("%s: invalid length on line %d", infile, lineno);
|
||||||
}
|
}
|
||||||
while (len <= maxlen) {
|
while (len <= maxlen) {
|
||||||
if (len == 0)
|
if (len == 0) {
|
||||||
puts("# word wrap disabled");
|
puts("# word wrap disabled");
|
||||||
else
|
} else {
|
||||||
printf("# word wrap at %zu characters\n", len);
|
printf("# word wrap at %u characters\n", len);
|
||||||
|
}
|
||||||
eventlog_writeln(stdout, lines[0], strlen(lines[0]), len);
|
eventlog_writeln(stdout, lines[0], strlen(lines[0]), len);
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
@@ -34,16 +34,21 @@ sudo_dso_public int main(int argc, char *argv[]);
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
size_t i;
|
unsigned int i;
|
||||||
|
|
||||||
#include "mksiglist.h"
|
#include "mksiglist.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For portability we must not use %zu below.
|
||||||
|
* This program is compiled with the host C compiler,
|
||||||
|
* so it cannot use any of the functions in libsudo_util.
|
||||||
|
*/
|
||||||
puts("const char *const sudo_sys_siglist[] = {");
|
puts("const char *const sudo_sys_siglist[] = {");
|
||||||
for (i = 0; i < nitems(sudo_sys_siglist); i++) {
|
for (i = 0; i < nitems(sudo_sys_siglist); i++) {
|
||||||
if (sudo_sys_siglist[i] != NULL) {
|
if (sudo_sys_siglist[i] != NULL) {
|
||||||
printf(" \"%s\",\n", sudo_sys_siglist[i]);
|
printf(" \"%s\",\n", sudo_sys_siglist[i]);
|
||||||
} else {
|
} else {
|
||||||
printf(" \"Signal %zu\",\n", i);
|
printf(" \"Signal %u\",\n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
puts("};");
|
puts("};");
|
||||||
|
@@ -34,16 +34,21 @@ sudo_dso_public int main(int argc, char *argv[]);
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
size_t i;
|
unsigned int i;
|
||||||
|
|
||||||
#include "mksigname.h"
|
#include "mksigname.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For portability we must not use %zu below.
|
||||||
|
* This program is compiled with the host C compiler,
|
||||||
|
* so it cannot use any of the functions in libsudo_util.
|
||||||
|
*/
|
||||||
puts("const char *const sudo_sys_signame[] = {");
|
puts("const char *const sudo_sys_signame[] = {");
|
||||||
for (i = 0; i < nitems(sudo_sys_signame); i++) {
|
for (i = 0; i < nitems(sudo_sys_signame); i++) {
|
||||||
if (sudo_sys_signame[i] != NULL) {
|
if (sudo_sys_signame[i] != NULL) {
|
||||||
printf(" \"%s\",\n", sudo_sys_signame[i]);
|
printf(" \"%s\",\n", sudo_sys_signame[i]);
|
||||||
} else {
|
} else {
|
||||||
printf(" \"Signal %zu\",\n", i);
|
printf(" \"Signal %u\",\n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
puts("};");
|
puts("};");
|
||||||
|
@@ -1118,7 +1118,7 @@ handle_server_hello(ServerHello *msg, struct client_closure *closure)
|
|||||||
if (msg->redirect != NULL && msg->redirect[0] != '\0')
|
if (msg->redirect != NULL && msg->redirect[0] != '\0')
|
||||||
printf("Redirect: %s\n", msg->redirect);
|
printf("Redirect: %s\n", msg->redirect);
|
||||||
for (n = 0; n < msg->n_servers; n++) {
|
for (n = 0; n < msg->n_servers; n++) {
|
||||||
printf("Server %zu: %s\n", n + 1, msg->servers[n]);
|
printf("Server %u: %s\n", (unsigned int)n + 1, msg->servers[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "iohelpers.h"
|
#include "iohelpers.h"
|
||||||
|
#include <sudo_fatal.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
rmdir_recursive(const char *path)
|
rmdir_recursive(const char *path)
|
||||||
@@ -69,7 +70,7 @@ freadall(const char *file_path, char *output, size_t max_len)
|
|||||||
int rc = false;
|
int rc = false;
|
||||||
FILE *file = fopen(file_path, "rb");
|
FILE *file = fopen(file_path, "rb");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
printf("Failed to open file '%s'\n", file_path);
|
sudo_warn_nodebug("failed to open file '%s'", file_path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +78,13 @@ freadall(const char *file_path, char *output, size_t max_len)
|
|||||||
output[len] = '\0';
|
output[len] = '\0';
|
||||||
|
|
||||||
if (ferror(file) != 0) {
|
if (ferror(file) != 0) {
|
||||||
printf("Failed to read file '%s' (Error %d)\n", file_path, ferror(file));
|
sudo_warn_nodebug("failed to read file '%s'", file_path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!feof(file)) {
|
if (!feof(file)) {
|
||||||
printf("File '%s' was bigger than allocated buffer %zu", file_path, max_len);
|
sudo_warn_nodebug("file '%s' was bigger than allocated buffer %zu",
|
||||||
|
file_path, max_len);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -163,20 +163,20 @@ valid_entry(union timestamp_entry_storage *u, off_t pos)
|
|||||||
switch (entry->version) {
|
switch (entry->version) {
|
||||||
case 1:
|
case 1:
|
||||||
if (entry->size != sizeof(struct timestamp_entry_v1)) {
|
if (entry->size != sizeof(struct timestamp_entry_v1)) {
|
||||||
printf("wrong sized v1 record @ %lld, got %hu, expected %zu\n",
|
sudo_warn("wrong sized v1 record @ %lld, got %hu, expected %zu",
|
||||||
(long long)pos, entry->size, sizeof(struct timestamp_entry_v1));
|
(long long)pos, entry->size, sizeof(struct timestamp_entry_v1));
|
||||||
debug_return_bool(false);
|
debug_return_bool(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (entry->size != sizeof(struct timestamp_entry)) {
|
if (entry->size != sizeof(struct timestamp_entry)) {
|
||||||
printf("wrong sized v2 record @ %lld, got %hu, expected %zu\n",
|
sudo_warn("wrong sized v2 record @ %lld, got %hu, expected %zu",
|
||||||
(long long)pos, entry->size, sizeof(struct timestamp_entry));
|
(long long)pos, entry->size, sizeof(struct timestamp_entry));
|
||||||
debug_return_bool(false);
|
debug_return_bool(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("unknown time stamp entry version %d @ %lld\n",
|
sudo_warn("unknown time stamp entry version %d @ %lld",
|
||||||
(int)entry->version, (long long)pos);
|
(int)entry->version, (long long)pos);
|
||||||
debug_return_bool(false);
|
debug_return_bool(false);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user