Bug Summary

File:src/usr.bin/rcs/rcsmerge.c
Warning:line 130, column 6
Null pointer passed as 1st argument to string comparison function

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 rcsmerge.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/usr.bin/rcs/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.bin/rcs -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.bin/rcs/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/usr.bin/rcs/rcsmerge.c
1/* $OpenBSD: rcsmerge.c,v 1.57 2016/08/26 09:02:54 guenther Exp $ */
2/*
3 * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <err.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <time.h>
32#include <unistd.h>
33
34#include "rcsprog.h"
35#include "diff.h"
36
37int
38rcsmerge_main(int argc, char **argv)
39{
40 int fd, ch, flags, kflag, status;
41 char fpath[PATH_MAX1024], r1[RCS_REV_BUFSZ64], r2[RCS_REV_BUFSZ64];
42 char *rev_str1, *rev_str2;
43 RCSFILE *file;
44 RCSNUM *rev1, *rev2;
45 BUF *bp;
46
47 flags = 0;
48 status = D_ERROR2;
49 rev1 = rev2 = NULL((void *)0);
50 rev_str1 = rev_str2 = NULL((void *)0);
1
Null pointer value stored to 'rev_str1'
51
52 while ((ch = rcs_getopt(argc, argv, "AEek:p::q::r::TVx::z:")) != -1) {
2
Assuming the condition is false
3
Loop condition is false. Execution continues on line 105
53 switch (ch) {
54 case 'A':
55 /*
56 * kept for compatibility
57 */
58 break;
59 case 'E':
60 flags |= MERGE_EFLAG(1<<16);
61 flags |= MERGE_OFLAG(1<<17);
62 break;
63 case 'e':
64 flags |= MERGE_EFLAG(1<<16);
65 break;
66 case 'k':
67 kflag = rcs_kflag_get(rcs_optarg);
68 if (RCS_KWEXP_INVAL(kflag)((kflag & 0x10) || ((kflag & 0x08) && (kflag &
~0x08)))
) {
69 warnx("invalid RCS keyword substitution mode");
70 (usage)();
71 }
72 break;
73 case 'p':
74 rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg);
75 flags |= PIPEOUT(1<<22);
76 break;
77 case 'q':
78 rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg);
79 flags |= QUIET(1<<24);
80 break;
81 case 'r':
82 rcs_setrevstr2(&rev_str1, &rev_str2,
83 rcs_optarg ? rcs_optarg : "");
84 break;
85 case 'T':
86 /*
87 * kept for compatibility
88 */
89 break;
90 case 'V':
91 printf("%s\n", rcs_version);
92 exit(0);
93 case 'x':
94 /* Use blank extension if none given. */
95 rcs_suffixes = rcs_optarg ? rcs_optarg : "";
96 break;
97 case 'z':
98 timezone_flag = rcs_optarg;
99 break;
100 default:
101 (usage)();
102 }
103 }
104
105 argc -= rcs_optind;
106 argv += rcs_optind;
107
108 if (rev_str1
3.1
'rev_str1' is equal to NULL
== NULL((void *)0)) {
4
Taking true branch
109 warnx("no base revision number given");
110 (usage)();
111 }
112
113 if (argc < 1) {
5
Assuming 'argc' is >= 1
6
Taking false branch
114 warnx("no input file");
115 (usage)();
116 }
117
118 if (argc > 2 || (argc == 2 && argv[1] != NULL((void *)0)))
7
Assuming 'argc' is > 2
119 warnx("warning: excess arguments ignored");
120
121 if ((fd = rcs_choosefile(argv[0], fpath, sizeof(fpath))) < 0)
8
Assuming the condition is false
9
Taking false branch
122 err(status, "%s", fpath);
123
124 if (!(flags & QUIET(1<<24)))
10
Taking true branch
125 (void)fprintf(stderr(&__sF[2]), "RCS file: %s\n", fpath);
126
127 if ((file = rcs_open(fpath, fd, RCS_READ(1<<0))) == NULL((void *)0))
11
Assuming the condition is false
12
Taking false branch
128 return (status);
129
130 if (strcmp(rev_str1, "") == 0) {
13
Null pointer passed as 1st argument to string comparison function
131 rev1 = rcsnum_alloc();
132 rcsnum_cpy(file->rf_head, rev1, 0);
133 } else if ((rev1 = rcs_getrevnum(rev_str1, file)) == NULL((void *)0))
134 errx(D_ERROR2, "invalid revision: %s", rev_str1);
135
136 if (rev_str2 != NULL((void *)0) && strcmp(rev_str2, "") != 0) {
137 if ((rev2 = rcs_getrevnum(rev_str2, file)) == NULL((void *)0))
138 errx(D_ERROR2, "invalid revision: %s", rev_str2);
139 } else {
140 rev2 = rcsnum_alloc();
141 rcsnum_cpy(file->rf_head, rev2, 0);
142 }
143
144 if (rcsnum_cmp(rev1, rev2, 0) == 0)
145 goto out;
146
147 if ((bp = rcs_diff3(file, argv[0], rev1, rev2, flags)) == NULL((void *)0))
148 errx(D_ERROR2, "failed to merge");
149
150 if (!(flags & QUIET(1<<24))) {
151 (void)rcsnum_tostr(rev1, r1, sizeof(r1));
152 (void)rcsnum_tostr(rev2, r2, sizeof(r2));
153
154 (void)fprintf(stderr(&__sF[2]), "Merging differences between %s and "
155 "%s into %s%s\n", r1, r2, argv[0],
156 (flags & PIPEOUT(1<<22)) ? "; result to stdout":"");
157 }
158
159 if (diff3_conflicts != 0)
160 status = D_OVERLAPS1;
161 else
162 status = 0;
163
164 if (flags & PIPEOUT(1<<22))
165 buf_write_fd(bp, STDOUT_FILENO1);
166 else {
167 /* XXX mode */
168 if (buf_write(bp, argv[0], 0644) < 0)
169 warnx("buf_write failed");
170
171 }
172
173 buf_free(bp);
174
175out:
176 rcs_close(file);
177 rcsnum_free(rev1);
178 rcsnum_free(rev2);
179 return (status);
180}
181
182__dead__attribute__((__noreturn__)) void
183rcsmerge_usage(void)
184{
185 fprintf(stderr(&__sF[2]),
186 "usage: rcsmerge [-EV] [-kmode] [-p[rev]] [-q[rev]]\n"
187 " [-xsuffixes] [-ztz] -rrev file ...\n");
188
189 exit(D_ERROR2);
190}