chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
siphash24: introduce state struct
[elogind.git]
/
src
/
basic
/
util.c
diff --git
a/src/basic/util.c
b/src/basic/util.c
index fcea9ceadaba2d3a5cf47a251d543550e58e56c2..6063b1beb548a2cf13652fa938a919834aed733a 100644
(file)
--- a/
src/basic/util.c
+++ b/
src/basic/util.c
@@
-72,7
+72,7
@@
#include "config.h"
#include "macro.h"
#include "util.h"
#include "config.h"
#include "macro.h"
#include "util.h"
-#include "ioprio.h"
+
//
#include "ioprio.h"
// #include "missing.h"
// #include "log.h"
#include "strv.h"
// #include "missing.h"
// #include "log.h"
#include "strv.h"
@@
-2125,7
+2125,13
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
assert(fd >= 0);
assert(buf);
assert(fd >= 0);
assert(buf);
- while (nbytes > 0) {
+ /* If called with nbytes == 0, let's call read() at least
+ * once, to validate the operation */
+
+ if (nbytes > (size_t) SSIZE_MAX)
+ return -EINVAL;
+
+ do {
ssize_t k;
k = read(fd, p, nbytes);
ssize_t k;
k = read(fd, p, nbytes);
@@
-2139,7
+2145,7
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
* and expect that any error/EOF is reported
* via read() */
* and expect that any error/EOF is reported
* via read() */
- fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
+
(void)
fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
continue;
}
continue;
}
@@
-2149,10
+2155,12
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
if (k == 0)
return n;
if (k == 0)
return n;
+ assert((size_t) k <= nbytes);
+
p += k;
nbytes -= k;
n += k;
p += k;
nbytes -= k;
n += k;
- }
+ }
while (nbytes > 0);
return n;
}
return n;
}
@@
-2162,9
+2170,10
@@
int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll) {
n = loop_read(fd, buf, nbytes, do_poll);
if (n < 0)
n = loop_read(fd, buf, nbytes, do_poll);
if (n < 0)
- return n;
+ return
(int)
n;
if ((size_t) n != nbytes)
return -EIO;
if ((size_t) n != nbytes)
return -EIO;
+
return 0;
}
return 0;
}
@@
-2174,7
+2183,8
@@
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
assert(fd >= 0);
assert(buf);
assert(fd >= 0);
assert(buf);
- errno = 0;
+ if (nbytes > (size_t) SSIZE_MAX)
+ return -EINVAL;
do {
ssize_t k;
do {
ssize_t k;
@@
-2189,16
+2199,18
@@
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
* and expect that any error/EOF is reported
* via write() */
* and expect that any error/EOF is reported
* via write() */
- fd_wait_for_event(fd, POLLOUT, USEC_INFINITY);
+
(void)
fd_wait_for_event(fd, POLLOUT, USEC_INFINITY);
continue;
}
return -errno;
}
continue;
}
return -errno;
}
- if (
nbytes > 0 && k == 0
) /* Can't really happen */
+ if (
_unlikely_(nbytes > 0 && k == 0)
) /* Can't really happen */
return -EIO;
return -EIO;
+ assert((size_t) k <= nbytes);
+
p += k;
nbytes -= k;
} while (nbytes > 0);
p += k;
nbytes -= k;
} while (nbytes > 0);
@@
-3677,7
+3689,6
@@
int block_get_whole_disk(dev_t d, dev_t *ret) {
return -ENOENT;
}
return -ENOENT;
}
-#endif // 0
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
@@
-3687,6
+3698,7
@@
static const char *const ioprio_class_table[] = {
};
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, INT_MAX);
};
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, INT_MAX);
+#endif // 0
static const char *const sigchld_code_table[] = {
[CLD_EXITED] = "exited",
static const char *const sigchld_code_table[] = {
[CLD_EXITED] = "exited",
@@
-6615,7
+6627,7
@@
ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
for (i = 0; i < len; ++i)
if (streq_ptr(table[i], key))
for (i = 0; i < len; ++i)
if (streq_ptr(table[i], key))
- return (ssize_t)i;
+ return (ssize_t)
i;
return -1;
}
return -1;
}
@@
-6671,7
+6683,6
@@
int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char
return 0;
}
return 0;
}
-#endif // 0
static char *strcpy_backslash_escaped(char *t, const char *s, const char *bad) {
assert(bad);
static char *strcpy_backslash_escaped(char *t, const char *s, const char *bad) {
assert(bad);
@@
-6732,6
+6743,7
@@
char *shell_maybe_quote(const char *s) {
return r;
}
return r;
}
+#endif // 0
int parse_mode(const char *s, mode_t *ret) {
char *x;
int parse_mode(const char *s, mode_t *ret) {
char *x;