Bug Summary

File:src/lib/librthread/rthread_fork.c
Warning:line 62, column 3
Return is prohibited after a successful vfork; call _exit() instead

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name rthread_fork.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/librthread/obj -resource-dir /usr/local/lib/clang/13.0.0 -include namespace.h -I /usr/src/lib/librthread -I /usr/src/lib/librthread/../libc/arch/amd64 -I /usr/src/lib/librthread/../libc/include -D FUTEX -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/librthread/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/lib/librthread/rthread_fork.c
1/* $OpenBSD: rthread_fork.c,v 1.23 2017/10/29 08:45:53 mpi Exp $ */
2
3/*
4 * Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
5 * Copyright (c) 2008 Philip Guenther <guenther@openbsd.org>
6 * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $
31 */
32
33#ifndef NO_PIC
34#include <sys/types.h>
35#include <elf.h>
36#pragma weak _DYNAMIC
37#endif
38
39#include <errno(*__errno()).h>
40#include <pthread.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <tib.h>
44#include <unistd.h>
45
46#include "rthread.h"
47#include "rthread_cb.h"
48
49/* make {fork,vfork,getthrid} call _thread_sys_{fork,vfork,getthrid} */
50REDIRECT_SYSCALL(fork)typeof(fork) fork asm("_thread_sys_""fork");
51REDIRECT_SYSCALL(vfork)typeof(vfork) vfork asm("_thread_sys_""vfork");
52REDIRECT_SYSCALL(getthrid)typeof(getthrid) getthrid asm("_thread_sys_""getthrid");
53
54static pid_t
55_dofork(pid_t (*sys_fork)(void))
56{
57 pthread_t me;
58 pid_t newid;
59 extern int _post_threaded;
60
61 if (!_threads_ready)
2
Assuming '_threads_ready' is 0
3
Taking true branch
62 return sys_fork();
4
Return is prohibited after a successful vfork; call _exit() instead
63
64 me = pthread_self();
65
66 /*
67 * Protect important libc/ld.so critical areas across the fork call.
68 * dlclose() will grab the atexit lock via __cxa_finalize() so lock
69 * the dl_lock first. malloc()/free() can use arc4random(), so lock
70 * malloc_lock before arc4_lock
71 */
72
73#ifndef NO_PIC
74 if (_DYNAMIC)
75 _rthread_dl_lock(0);
76#endif
77
78 newid = _thread_dofork(sys_fork);
79
80 if (newid == 0) {
81 struct tib *tib = me->tib;
82#ifndef NO_PIC
83 /* reinitialize the lock in the child */
84 if (_DYNAMIC)
85 _rthread_dl_lock(2);
86#endif
87 /* update this thread's structure */
88 tib->tib_tid = getthrid();
89 me->donesem.lock = _SPINLOCK_UNLOCKED(0);
90 me->flags_lock = _SPINLOCK_UNLOCKED(0);
91
92 /* reinit the thread list */
93 LIST_INIT(&_thread_list)do { ((&_thread_list)->lh_first) = ((void*)0); } while
(0)
;
94 LIST_INSERT_HEAD(&_thread_list, me, threads)do { if (((me)->threads.le_next = (&_thread_list)->
lh_first) != ((void*)0)) (&_thread_list)->lh_first->
threads.le_prev = &(me)->threads.le_next; (&_thread_list
)->lh_first = (me); (me)->threads.le_prev = &(&
_thread_list)->lh_first; } while (0)
;
95 _thread_lock = _SPINLOCK_UNLOCKED(0);
96
97 /* single threaded now */
98 __isthreaded = 0;
99 _post_threaded = 0; /* notyet... */
100 }
101#ifndef NO_PIC
102 else if (_DYNAMIC)
103 _rthread_dl_lock(1);
104#endif
105 return newid;
106}
107
108pid_t
109_thread_fork(void)
110{
111 return _dofork(&fork);
112}
113
114pid_t
115_thread_vfork(void)
116{
117 return _dofork(&vfork);
1
Calling '_dofork'
118}