Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173158933
D55258.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D55258.diff
View Options
diff --git a/usr.sbin/ngctl/write.c b/usr.sbin/ngctl/write.c
--- a/usr.sbin/ngctl/write.c
+++ b/usr.sbin/ngctl/write.c
@@ -34,10 +34,12 @@
#include <sys/socket.h>
#include <err.h>
+#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <netgraph/ng_message.h>
#include <netgraph/ng_socket.h>
#include "ngctl.h"
@@ -62,6 +64,7 @@
struct sockaddr_ng *sag = (struct sockaddr_ng *)sagbuf;
u_char buf[BUF_SIZE];
const char *hook;
+ size_t hooklen;
FILE *fp;
u_int len;
int byte;
@@ -71,6 +74,14 @@
if (ac < 3)
return (CMDRTN_USAGE);
hook = av[1];
+ _Static_assert(sizeof(sagbuf) >=
+ offsetof(struct sockaddr_ng, sg_data) + NG_HOOKSIZ,
+ "sagbuf is too small for NG_HOOKSIZ");
+ hooklen = strlcpy(sag->sg_data, hook, NG_HOOKSIZ);
+ if (hooklen >= NG_HOOKSIZ) {
+ warnx("hook name \"%s\" too long", hook);
+ return (CMDRTN_ERROR);
+ }
/* Get data */
if (strcmp(av[2], "-f") == 0) {
@@ -103,11 +114,10 @@
}
/* Send data */
- sag->sg_len = 3 + strlen(hook);
+ sag->sg_len = 3 + hooklen;
sag->sg_family = AF_NETGRAPH;
- strlcpy(sag->sg_data, hook, sizeof(sagbuf) - 2);
- if (sendto(dsock, buf, len,
- 0, (struct sockaddr *)sag, sag->sg_len) == -1) {
+ if (sendto(dsock, buf, len, 0, (struct sockaddr *)sag,
+ sag->sg_len) < 0) {
warn("writing to hook \"%s\"", hook);
return (CMDRTN_ERROR);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Sep 25, 12:33 AM (4 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39561982
Default Alt Text
D55258.diff (1 KB)
Attached To
Mode
D55258: ngctl: Check hook name length
Attached
Detach File
Event Timeline
Log In to Comment