| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $ */ | | 1 | /* $NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __RCSID("$NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $"); | | 34 | __RCSID("$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $"); |
35 | #endif | | 35 | #endif |
36 | | | 36 | |
37 | #include <sys/stat.h> | | 37 | #include <sys/stat.h> |
38 | | | 38 | |
39 | #include <time.h> | | 39 | #include <time.h> |
40 | #include <string.h> | | 40 | #include <string.h> |
41 | #include <err.h> | | 41 | #include <err.h> |
42 | #include <stdlib.h> | | 42 | #include <stdlib.h> |
43 | | | 43 | |
44 | #ifdef SUPPORT_UTMP | | 44 | #ifdef SUPPORT_UTMP |
45 | #include <utmp.h> | | 45 | #include <utmp.h> |
46 | #endif | | 46 | #endif |
47 | #ifdef SUPPORT_UTMPX | | 47 | #ifdef SUPPORT_UTMPX |
| @@ -268,62 +268,62 @@ getutentries(const char *fname, struct u | | | @@ -268,62 +268,62 @@ getutentries(const char *fname, struct u |
268 | } | | 268 | } |
269 | | | 269 | |
270 | #ifdef SUPPORT_UTMP | | 270 | #ifdef SUPPORT_UTMP |
271 | static void | | 271 | static void |
272 | getentry(struct utmpentry *e, struct utmp *up) | | 272 | getentry(struct utmpentry *e, struct utmp *up) |
273 | { | | 273 | { |
274 | COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); | | 274 | COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); |
275 | COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); | | 275 | COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); |
276 | COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); | | 276 | COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); |
277 | | | 277 | |
278 | /* | | 278 | /* |
279 | * e has just been calloc'd. We don't need to clear it or | | 279 | * e has just been calloc'd. We don't need to clear it or |
280 | * append null-terminators, because its length is strictly | | 280 | * append null-terminators, because its length is strictly |
281 | * greater than the source string. Use strncpy to _read_ | | 281 | * greater than the source string. Use memcpy to _read_ |
282 | * up->ut_* because they may not be terminated. For this | | 282 | * up->ut_* because they may not be terminated. For this |
283 | * reason we use the size of the _source_ as the length | | 283 | * reason we use the size of the _source_ as the length |
284 | * argument. | | 284 | * argument. |
285 | */ | | 285 | */ |
286 | (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name)); | | 286 | memcpy(e->name, up->ut_name, sizeof(up->ut_name)); |
287 | (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line)); | | 287 | memcpy(e->line, up->ut_line, sizeof(up->ut_line)); |
288 | (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host)); | | 288 | memcpy(e->host, up->ut_host, sizeof(up->ut_host)); |
289 | | | 289 | |
290 | e->tv.tv_sec = up->ut_time; | | 290 | e->tv.tv_sec = up->ut_time; |
291 | e->tv.tv_usec = 0; | | 291 | e->tv.tv_usec = 0; |
292 | e->pid = 0; | | 292 | e->pid = 0; |
293 | e->term = 0; | | 293 | e->term = 0; |
294 | e->exit = 0; | | 294 | e->exit = 0; |
295 | e->sess = 0; | | 295 | e->sess = 0; |
296 | e->type = USER_PROCESS; | | 296 | e->type = USER_PROCESS; |
297 | adjust_size(e); | | 297 | adjust_size(e); |
298 | } | | 298 | } |
299 | #endif | | 299 | #endif |
300 | | | 300 | |
301 | #ifdef SUPPORT_UTMPX | | 301 | #ifdef SUPPORT_UTMPX |
302 | static void | | 302 | static void |
303 | getentryx(struct utmpentry *e, struct utmpx *up) | | 303 | getentryx(struct utmpentry *e, struct utmpx *up) |
304 | { | | 304 | { |
305 | COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); | | 305 | COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); |
306 | COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); | | 306 | COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); |
307 | COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); | | 307 | COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); |
308 | | | 308 | |
309 | /* | | 309 | /* |
310 | * e has just been calloc'd. We don't need to clear it or | | 310 | * e has just been calloc'd. We don't need to clear it or |
311 | * append null-terminators, because its length is strictly | | 311 | * append null-terminators, because its length is strictly |
312 | * greater than the source string. Use strncpy to _read_ | | 312 | * greater than the source string. Use memcpy to _read_ |
313 | * up->ut_* because they may not be terminated. For this | | 313 | * up->ut_* because they may not be terminated. For this |
314 | * reason we use the size of the _source_ as the length | | 314 | * reason we use the size of the _source_ as the length |
315 | * argument. | | 315 | * argument. |
316 | */ | | 316 | */ |
317 | (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name)); | | 317 | memcpy(e->name, up->ut_name, sizeof(up->ut_name)); |
318 | (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line)); | | 318 | memcpy(e->line, up->ut_line, sizeof(up->ut_line)); |
319 | (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host)); | | 319 | memcpy(e->host, up->ut_host, sizeof(up->ut_host)); |
320 | | | 320 | |
321 | e->tv = up->ut_tv; | | 321 | e->tv = up->ut_tv; |
322 | e->pid = up->ut_pid; | | 322 | e->pid = up->ut_pid; |
323 | e->term = up->ut_exit.e_termination; | | 323 | e->term = up->ut_exit.e_termination; |
324 | e->exit = up->ut_exit.e_exit; | | 324 | e->exit = up->ut_exit.e_exit; |
325 | e->sess = up->ut_session; | | 325 | e->sess = up->ut_session; |
326 | e->type = up->ut_type; | | 326 | e->type = up->ut_type; |
327 | adjust_size(e); | | 327 | adjust_size(e); |
328 | } | | 328 | } |
329 | #endif | | 329 | #endif |