chiark / gitweb /
journal: export valid_user_field and size defines
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 3 Nov 2012 19:13:46 +0000 (20:13 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Mar 2014 05:55:47 +0000 (01:55 -0400)
In preparation for use elsewhere.

src/journal/coredump.c
src/journal/journald-native.c
src/journal/journald-native.h

index 733373b3071d16a70710aa19e9f034ae181bf729..29342de6811d25fbe48123cd063b5cd0edd0c790 100644 (file)
 #include "mkdir.h"
 #include "special.h"
 #include "cgroup-util.h"
+#include "journald-native.h"
 
 /* Few programs have less than 3MiB resident */
 #define COREDUMP_MIN_START (3*1024*1024)
 /* Make sure to not make this larger than the maximum journal entry
  * size. See ENTRY_SIZE_MAX in journald-native.c. */
 #define COREDUMP_MAX (767*1024*1024)
+assert_cc(COREDUMP_MAX <= ENTRY_SIZE_MAX);
 
 enum {
         ARG_PID = 1,
index 0509c1eaeed31e8d62d9ad34673021985ad23aed..c54f6475d330dc70c18eefc02cd635e70a0b1696 100644 (file)
 #include "journald-syslog.h"
 #include "journald-wall.h"
 
-/* Make sure not to make this smaller than the maximum coredump
- * size. See COREDUMP_MAX in coredump.c */
-#define ENTRY_SIZE_MAX (1024*1024*768)
-#define DATA_SIZE_MAX (1024*1024*768)
-
-static bool valid_user_field(const char *p, size_t l) {
+bool valid_user_field(const char *p, size_t l, bool allow_protected) {
         const char *a;
 
         /* We kinda enforce POSIX syntax recommendations for
@@ -56,7 +51,7 @@ static bool valid_user_field(const char *p, size_t l) {
                 return false;
 
         /* Variables starting with an underscore are protected */
-        if (p[0] == '_')
+        if (!allow_protected && p[0] == '_')
                 return false;
 
         /* Don't allow digits as first character */
@@ -65,9 +60,9 @@ static bool valid_user_field(const char *p, size_t l) {
 
         /* Only allow A-Z0-9 and '_' */
         for (a = p; a < p + l; a++)
-                if (!((*a >= 'A' && *a <= 'Z') ||
-                      (*a >= '0' && *a <= '9') ||
-                      *a == '_'))
+                if ((*a < 'A' || *a > 'Z') &&
+                    (*a < '0' || *a > '9') &&
+                    *a != '_')
                         return false;
 
         return true;
@@ -139,7 +134,7 @@ void server_process_native_message(
 
                 q = memchr(p, '=', e - p);
                 if (q) {
-                        if (valid_user_field(p, q - p)) {
+                        if (valid_user_field(p, q - p, false)) {
                                 size_t l;
 
                                 l = e - p;
@@ -239,7 +234,7 @@ void server_process_native_message(
                         k[e - p] = '=';
                         memcpy(k + (e - p) + 1, e + 1 + sizeof(uint64_t), l);
 
-                        if (valid_user_field(p, e - p)) {
+                        if (valid_user_field(p, e - p, false)) {
                                 iovec[n].iov_base = k;
                                 iovec[n].iov_len = (e - p) + 1 + l;
                                 n++;
index 16c09f523e9f16302755f1d1263cd4e9eb480a37..bf02fee576e243686c7256b4eefeed84d14fe9e1 100644 (file)
 
 #include "journald-server.h"
 
+/* Make sure not to make this smaller than the maximum coredump
+ * size. See COREDUMP_MAX in coredump.c */
+#define ENTRY_SIZE_MAX (1024*1024*768)
+#define DATA_SIZE_MAX (1024*1024*768)
+
+bool valid_user_field(const char *p, size_t l, bool allow_protected);
+
 void server_process_native_message(Server *s, const void *buffer, size_t buffer_size, struct ucred *ucred, struct timeval *tv, const char *label, size_t label_len);
 
 void server_process_native_file(Server *s, int fd, struct ucred *ucred, struct timeval *tv, const char *label, size_t label_len);