chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
socket-util: socket_address_parse() should not log errors on its own
[elogind.git]
/
src
/
shared
/
bus-label.c
diff --git
a/src/shared/bus-label.c
b/src/shared/bus-label.c
index 61eb75bca28490decd8c9d924fa265525eac7934..ccc9f2bf8e58df7c6047bafc13b22c127e77b0bb 100644
(file)
--- a/
src/shared/bus-label.c
+++ b/
src/shared/bus-label.c
@@
-19,13
+19,10
@@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <assert.h>
#include <stdlib.h>
#include <stdlib.h>
-#include <unistd.h>
#include "util.h"
#include "macro.h"
#include "util.h"
#include "macro.h"
-#include "def.h"
#include "bus-label.h"
#include "bus-label.h"
@@
-66,34
+63,35
@@
char *bus_label_escape(const char *s) {
return r;
}
return r;
}
-char *bus_label_unescape
(const char *f
) {
+char *bus_label_unescape
_n(const char *f, size_t l
) {
char *r, *t;
char *r, *t;
+ size_t i;
assert_return(f, NULL);
/* Special case for the empty string */
assert_return(f, NULL);
/* Special case for the empty string */
- if (
streq(f, "_")
)
+ if (
l == 1 && *f == '_'
)
return strdup("");
return strdup("");
- r = new(char,
strlen(f)
+ 1);
+ r = new(char,
l
+ 1);
if (!r)
return NULL;
if (!r)
return NULL;
- for (t = r; *f; f++) {
-
- if (*f == '_') {
+ for (i = 0, t = r; i < l; ++i) {
+ if (f[i] == '_') {
int a, b;
int a, b;
- if ((a = unhexchar(f[1])) < 0 ||
- (b = unhexchar(f[2])) < 0) {
+ if (l - i < 3 ||
+ (a = unhexchar(f[i + 1])) < 0 ||
+ (b = unhexchar(f[i + 2])) < 0) {
/* Invalid escape code, let's take it literal then */
*(t++) = '_';
} else {
*(t++) = (char) ((a << 4) | b);
/* Invalid escape code, let's take it literal then */
*(t++) = '_';
} else {
*(t++) = (char) ((a << 4) | b);
-
f
+= 2;
+
i
+= 2;
}
} else
}
} else
- *(t++) =
*f
;
+ *(t++) =
f[i]
;
}
*t = 0;
}
*t = 0;