summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/client.c3
-rw-r--r--lib/server.c7
-rw-r--r--lib/utils.c7
3 files changed, 11 insertions, 6 deletions
diff --git a/lib/client.c b/lib/client.c
index f1c4da1..d101223 100644
--- a/lib/client.c
+++ b/lib/client.c
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: MIT
*/
+#include <alloca.h>
#include "private.h"
#include "protocol.h"
#include "sender.h"
@@ -50,7 +51,7 @@ bool icipc_client_send_request(
return false;
const size_t size = icipc_protocol_calculate_request_size(name, args);
- uint8_t buffer[size];
+ uint8_t *buffer = alloca(size);
icipc_protocol_build_request(buffer, size, name, args);
return icipc_sender_send(base, buffer, size, reply, data);
}
diff --git a/lib/server.c b/lib/server.c
index 6229ecd..6a67395 100644
--- a/lib/server.c
+++ b/lib/server.c
@@ -8,6 +8,7 @@
#include <pthread.h>
#include <string.h>
+#include <alloca.h>
#include "private.h"
#include "protocol.h"
@@ -69,7 +70,7 @@ static bool handle_message(
if (!icipc_protocol_parse_request(buffer, size, &name, &args)) {
const char *msg = "could not parse request";
const size_t s = icipc_protocol_calculate_reply_error_size(msg);
- uint8_t b[s];
+ uint8_t *b = alloca(s);
icipc_protocol_build_reply_error(b, s, msg);
return icipc_socket_write(sender_fd, b, s) == (ssize_t) s;
}
@@ -234,7 +235,7 @@ bool icipc_server_reply_ok(
int client_fd,
const struct icipc_data *value) {
const size_t s = icipc_protocol_calculate_reply_ok_size(value);
- uint8_t b[s];
+ uint8_t *b = alloca(s);
icipc_protocol_build_reply_ok(b, s, value);
return icipc_socket_write(client_fd, b, s) == (ssize_t) s;
}
@@ -247,7 +248,7 @@ bool icipc_server_reply_error(
return false;
const size_t s = icipc_protocol_calculate_reply_error_size(msg);
- uint8_t b[s];
+ uint8_t *b = alloca(s);
icipc_protocol_build_reply_error(b, s, msg);
return icipc_socket_write(client_fd, b, s) == (ssize_t) s;
}
diff --git a/lib/utils.c b/lib/utils.c
index 4d91241..37bcce9 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -91,7 +91,6 @@ int icipc_construct_socket_path(const char *name, char *buf, size_t buf_size) {
bool path_is_absolute;
const char *runtime_dir = NULL;
struct passwd pwd, *result = NULL;
- char buffer[4096];
int name_size;
path_is_absolute = name[0] == '/';
@@ -105,8 +104,12 @@ int icipc_construct_socket_path(const char *name, char *buf, size_t buf_size) {
if (runtime_dir == NULL)
runtime_dir = getenv("USERPROFILE");
if (runtime_dir == NULL) {
+ long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+ if (bufsize == -1)
+ bufsize = 4096;
+ char *buffer = alloca(bufsize);
if (getpwuid_r
- (getuid(), &pwd, buffer, sizeof(buffer),
+ (getuid(), &pwd, buffer, bufsize,
&result) == 0)
runtime_dir = result ? result->pw_dir : NULL;
}