Skip to content

Commit a4480b0

Browse files
authored
Merge pull request #1490 from ddpbsd/coverity_20180806
Coverity fixes
2 parents 8e492f9 + 2f1d02f commit a4480b0

File tree

10 files changed

+50
-7
lines changed

10 files changed

+50
-7
lines changed

src/addagent/validate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ int OS_RemoveAgent(const char *u_id) {
100100
return 0;
101101

102102
#ifndef WIN32
103-
chmod(AUTH_FILE, 0440);
103+
if((chmod(AUTH_FILE, 0440)) < 0) {
104+
merror("addagent: ERROR: Cannot chmod %s: %s", AUTH_FILE, strerror(errno));
105+
}
104106
#endif
105107

106108
#ifdef REUSE_ID

src/monitord/sendcustomemail.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ int OS_SendCustomEmail2(char **to, char *subject, char *smtpserver, char *from,
191191
if (replyto) {
192192
memset(snd_msg, '\0', 128);
193193
snprintf(snd_msg, 127, REPLYTO, replyto);
194-
OS_SendTCP(socket, snd_msg);
194+
if(sendmail) {
195+
fprintf(sendmail, "%s", snd_msg);
196+
} else {
197+
OS_SendTCP(socket, snd_msg);
198+
}
199+
195200
}
196201

197202
/* Add CCs */
@@ -269,6 +274,12 @@ int OS_SendCustomEmail2(char **to, char *subject, char *smtpserver, char *from,
269274
fp = fopen(fname2, "r");
270275
if(!fp) {
271276
merror("%s: ERROR: Cannot open %s: %s", __local_name, fname2, strerror(errno));
277+
if(socket) {
278+
close(socket);
279+
}
280+
if(sendmail) {
281+
pclose(sendmail);
282+
}
272283
return(1);
273284
}
274285

src/os_auth/main-server.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ char *__generatetmppass()
109109
snprintf(str1, STR_SIZE, "%d%d%s%d%s%s",(int)time(0), rand1, muname, rand2, md3, md4);
110110
OS_MD5_Str(str1, md1);
111111
fstring = strdup(md1);
112+
free(rand3);
113+
free(rand4);
114+
if(muname) {
115+
free(muname);
116+
}
112117
return(fstring);
113118
}
114119

src/os_maild/sendcustomemail.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, c
191191
if (replyto) {
192192
memset(snd_msg, '\0', 128);
193193
snprintf(snd_msg, 127, REPLYTO, replyto);
194-
OS_SendTCP(socket, snd_msg);
194+
if(sendmail) {
195+
fprintf(sendmail, "%s", snd_msg);
196+
} else {
197+
OS_SendTCP(socket, snd_msg);
198+
}
195199
}
196200

197201
/* Add CCs */
@@ -260,6 +264,12 @@ int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, c
260264
fp = fopen(fname, "r");
261265
if(!fp) {
262266
merror("%s: ERROR: Cannot open %s: %s", __local_name, fname, strerror(errno));
267+
if(socket) {
268+
close(socket);
269+
}
270+
if(sendmail) {
271+
pclose(sendmail);
272+
}
263273
return(1);
264274
}
265275

src/os_net/os_net.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ int OS_Connect(char *_port, unsigned int protocol, const char *_ip)
371371
s = getaddrinfo(_ip, _port, &hints, &result);
372372
if (s != 0) {
373373
verbose("getaddrinfo: %s", gai_strerror(s));
374+
if(result) {
375+
freeaddrinfo(result);
376+
}
374377
return(OS_INVALID);
375378
}
376379

@@ -401,6 +404,9 @@ int OS_Connect(char *_port, unsigned int protocol, const char *_ip)
401404
}
402405
if (rp == NULL) { /* No address succeeded */
403406
OS_CloseSocket(ossock);
407+
if(result) {
408+
freeaddrinfo(result);
409+
}
404410
return(OS_SOCKTERR);
405411
}
406412
satop(rp->ai_addr, tempaddr, sizeof tempaddr);

src/shared/file_op.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ char *GetRandomNoise()
366366
{
367367
FILE *fp;
368368
char buf[2048 + 1];
369+
size_t frr = 0;
369370

370371
/* Reading urandom */
371372
fp = fopen("/dev/urandom", "r");
@@ -375,7 +376,12 @@ char *GetRandomNoise()
375376
}
376377

377378
buf[2048] = '\0';
378-
fread(buf, 1, 2048, fp);
379+
frr = fread(buf, 1, 2048, fp);
380+
if(frr == 0) {
381+
merror("ERROR: GetRandomNoise() fread() returned 0.");
382+
fclose(fp);
383+
return(NULL);
384+
}
379385
return(strdup(buf));
380386
}
381387

src/shared/rules_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ int OS_ReadXMLRules(const char *rulefile,
609609
config_ruleinfo->ckignore |= FTS_LOCATION;
610610
}
611611
if (strstr(rule_opt[k]->content, "data") != NULL) {
612-
config_ruleinfo->ignore |= FTS_DATA;
612+
config_ruleinfo->ckignore |= FTS_DATA;
613613
}
614614
if (strstr(rule_opt[k]->content, "name") != NULL) {
615615
config_ruleinfo->ckignore |= FTS_NAME;

src/shared/validate_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int sacmp(struct sockaddr *sa1, struct sockaddr *sa2, int prefixlength)
382382
realaf2 = AF_INET6;
383383
if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *) addr2)) {
384384
/* shift the pointer for a mapped address */
385-
addr1 += (sizeof (struct in6_addr)) - (sizeof (struct in_addr));
385+
addr2 += (sizeof (struct in6_addr)) - (sizeof (struct in_addr));
386386
realaf2 = AF_INET;
387387
}
388388
break;

src/syscheckd/run_realtime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ int realtime_process()
184184
if (len < 0) {
185185
merror("%s: ERROR: Unable to read from real time buffer.", ARGV0);
186186
} else if (len > 0) {
187+
buf[len] = '\0';
187188
while (i < (size_t) len) {
188189
event = (struct inotify_event *) (void *) &buf[i];
189190

src/syscheckd/seechanges.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ char *seechanges_addfile(const char *filename)
299299
);
300300

301301

302-
rename(old_location, tmp_location);
302+
if((rename(old_location, tmp_location)) < 0) {
303+
merror("%s: ERROR rename of %s failed: %s", ARGV0, old_location, strerror(errno));
304+
}
303305
if(seechanges_dupfile(filename, old_location) != 1)
304306
{
305307
merror("%s: ERROR: Unable to create snapshot for %s",ARGV0, filename);

0 commit comments

Comments
 (0)