hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/sunrpc/addr.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2009, Oracle. All rights reserved.
34 *
....@@ -161,8 +162,10 @@
161162 const size_t buflen, const char *delim,
162163 struct sockaddr_in6 *sin6)
163164 {
164
- char *p;
165
+ char p[IPV6_SCOPE_ID_LEN + 1];
165166 size_t len;
167
+ u32 scope_id = 0;
168
+ struct net_device *dev;
166169
167170 if ((buf + buflen) == delim)
168171 return 1;
....@@ -174,29 +177,23 @@
174177 return 0;
175178
176179 len = (buf + buflen) - delim - 1;
177
- p = kstrndup(delim + 1, len, GFP_KERNEL);
178
- if (p) {
179
- u32 scope_id = 0;
180
- struct net_device *dev;
180
+ if (len > IPV6_SCOPE_ID_LEN)
181
+ return 0;
181182
182
- dev = dev_get_by_name(net, p);
183
- if (dev != NULL) {
184
- scope_id = dev->ifindex;
185
- dev_put(dev);
186
- } else {
187
- if (kstrtou32(p, 10, &scope_id) != 0) {
188
- kfree(p);
189
- return 0;
190
- }
191
- }
183
+ memcpy(p, delim + 1, len);
184
+ p[len] = 0;
192185
193
- kfree(p);
194
-
195
- sin6->sin6_scope_id = scope_id;
196
- return 1;
186
+ dev = dev_get_by_name(net, p);
187
+ if (dev != NULL) {
188
+ scope_id = dev->ifindex;
189
+ dev_put(dev);
190
+ } else {
191
+ if (kstrtou32(p, 10, &scope_id) != 0)
192
+ return 0;
197193 }
198194
199
- return 0;
195
+ sin6->sin6_scope_id = scope_id;
196
+ return 1;
200197 }
201198
202199 static size_t rpc_pton6(struct net *net, const char *buf, const size_t buflen,