chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tests: add tests for environment serialization
[elogind.git]
/
src
/
basic
/
hexdecoct.c
diff --git
a/src/basic/hexdecoct.c
b/src/basic/hexdecoct.c
index 7e84550b6d49770175ac478be79768ea10a38ad0..2d6e377f0a4062cbdc693d103bfb45a21a3c4b63 100644
(file)
--- a/
src/basic/hexdecoct.c
+++ b/
src/basic/hexdecoct.c
@@
-1,5
+1,3
@@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
/***
This file is part of systemd.
@@
-20,10
+18,13
@@
***/
#include <ctype.h>
***/
#include <ctype.h>
-#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
#include "alloc-util.h"
#include "hexdecoct.h"
#include "alloc-util.h"
#include "hexdecoct.h"
+#include "macro.h"
#include "util.h"
char octchar(int x) {
#include "util.h"
char octchar(int x) {
@@
-71,10
+72,10
@@
int unhexchar(char c) {
}
char *hexmem(const void *p, size_t l) {
}
char *hexmem(const void *p, size_t l) {
- char *r, *z;
const uint8_t *x;
const uint8_t *x;
+ char *r, *z;
- z = r =
malloc(
l * 2 + 1);
+ z = r =
new(char,
l * 2 + 1);
if (!r)
return NULL;
if (!r)
return NULL;
@@
-96,6
+97,9
@@
int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
assert(len);
assert(p);
assert(len);
assert(p);
+ if (l % 2 != 0)
+ return -EINVAL;
+
z = r = malloc((l + 1) / 2 + 1);
if (!r)
return -ENOMEM;
z = r = malloc((l + 1) / 2 + 1);
if (!r)
return -ENOMEM;
@@
-106,12
+110,10
@@
int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
a = unhexchar(x[0]);
if (a < 0)
return a;
a = unhexchar(x[0]);
if (a < 0)
return a;
- else if (x+1 < p + l) {
- b = unhexchar(x[1]);
- if (b < 0)
- return b;
- } else
- b = 0;
+
+ b = unhexchar(x[1]);
+ if (b < 0)
+ return b;
*(z++) = (uint8_t) a << 4 | (uint8_t) b;
}
*(z++) = (uint8_t) a << 4 | (uint8_t) b;
}
@@
-275,8
+277,8
@@
int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_l
if (padding) {
/* strip the padding */
while (l > 0 && p[l - 1] == '=' && pad < 7) {
if (padding) {
/* strip the padding */
while (l > 0 && p[l - 1] == '=' && pad < 7) {
- pad
++;
- l
--;
+ pad++;
+ l--;
}
}
}
}
@@
-504,7
+506,7
@@
int unbase64char(char c) {
if (c == '+')
return offset;
if (c == '+')
return offset;
- offset
++;
+ offset++;
if (c == '/')
return offset;
if (c == '/')
return offset;
@@
-572,7
+574,7
@@
static int base64_append_width(char **prefix, int plen,
if (!t)
return -ENOMEM;
if (!t)
return -ENOMEM;
- memcpy(t + plen, sep, slen);
+ memcpy
_safe
(t + plen, sep, slen);
for (line = 0, s = t + plen + slen, avail = len; line < lines; line++) {
int act = MIN(width, avail);
for (line = 0, s = t + plen + slen, avail = len; line < lines; line++) {
int act = MIN(width, avail);
@@
-620,9
+622,9
@@
int unbase64mem(const char *p, size_t l, void **mem, size_t *_len) {
/* strip the padding */
if (l > 0 && p[l - 1] == '=')
/* strip the padding */
if (l > 0 && p[l - 1] == '=')
- l
--;
+ l--;
if (l > 0 && p[l - 1] == '=')
if (l > 0 && p[l - 1] == '=')
- l
--;
+ l--;
/* a group of four input bytes needs three output bytes, in case of
padding we need to add two or three extra bytes */
/* a group of four input bytes needs three output bytes, in case of
padding we need to add two or three extra bytes */