Introduce sc_arg_max() helper
Just a cast and an assert.
This commit is contained in:
@@ -72,7 +72,7 @@ bool env_value_is_valid(const char *e) {
|
||||
* either. Discounting the shortest possible variable name of
|
||||
* length 1, the equal sign and trailing NUL this hence leaves
|
||||
* ARG_MAX-3 as longest possible variable value. */
|
||||
if (strlen(e) > (size_t) sysconf(_SC_ARG_MAX) - 3)
|
||||
if (strlen(e) > sc_arg_max() - 3)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -95,7 +95,7 @@ bool env_assignment_is_valid(const char *e) {
|
||||
* be > ARG_MAX, hence the individual variable assignments
|
||||
* cannot be either, but let's leave room for one trailing NUL
|
||||
* byte. */
|
||||
if (strlen(e) > (size_t) sysconf(_SC_ARG_MAX) - 1)
|
||||
if (strlen(e) > sc_arg_max() - 1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -4,10 +4,17 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "string.h"
|
||||
|
||||
static inline size_t sc_arg_max(void) {
|
||||
long l = sysconf(_SC_ARG_MAX);
|
||||
assert(l > 0);
|
||||
return (size_t) l;
|
||||
}
|
||||
|
||||
bool env_name_is_valid(const char *e);
|
||||
bool env_value_is_valid(const char *e);
|
||||
bool env_assignment_is_valid(const char *e);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "architecture.h"
|
||||
#include "escape.h"
|
||||
#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
@@ -126,12 +127,9 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (max_length == 0) {
|
||||
if (max_length == 0)
|
||||
/* This is supposed to be a safety guard against runaway command lines. */
|
||||
long l = sysconf(_SC_ARG_MAX);
|
||||
assert(l > 0);
|
||||
max_length = l;
|
||||
}
|
||||
max_length = sc_arg_max();
|
||||
|
||||
if (max_length == 1) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user