1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

libtt: Further coverity fixes

This commit is contained in:
Peter Howkins 2018-04-20 22:57:47 +01:00
parent f905d25392
commit 22071fd62a
12 changed files with 79 additions and 19 deletions

View file

@ -1561,7 +1561,10 @@ _tt_transaction_1(_Tt_transaction_args* args, SVCXPRT * /* transp */)
return _tt_transaction_error(fd);
}
/* Turn on close-on-exec */
fcntl(fd, F_SETFD, 1);
if(fcntl(fd, F_SETFD, 1) == -1) {
res.iserrno = DM_WRITE_FAILED;
return _tt_transaction_error(fd);
}
/* reset to beginning of file */
off_t offset;

View file

@ -251,12 +251,12 @@ int main(int argc, char **argv)
_tt_syslog( errstr, LOG_ERR, "%m" );
exit(1);
}
cargv[i] = '\0';
cargv[i] = NULL;
// if no program given then use $SHELL
if (! cargv[0]) {
cargv[0] = getenv("SHELL");
cargv[1] = '\0';
cargv[1] = NULL;
}
cmd = cargv[0];
background_mode = 0;

View file

@ -1540,7 +1540,11 @@ _tt_session_types_load(const char *filename)
if (-1==(fd=open(filename, O_RDONLY))) {
return TT_ERR_FILE;
}
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if (-1==fcntl(fd, F_SETFD, 1)) {
close(fd);
return TT_ERR_FILE;
}
if (-1==fstat(fd, &typefile_stat)) {
close(fd);

View file

@ -173,6 +173,7 @@ read_auth_entries(FILE *fp, _tt_AuthFileEntryList **headp)
_tt_syslog(0, LOG_ERR,
"%s: memory error. New entry not written.\n",
funcname);
free(entry);
return TT_ERR_NOMEM;
}

View file

@ -88,6 +88,8 @@ _Tt_stream_socket()
_sock = -1;
_hostaddr.sin_port = 0;
_hostaddr.sin_family = 0;
memset(&_hostaddr.sin_addr, 0, sizeof(struct in_addr));
}
_Tt_stream_socket::
@ -557,7 +559,7 @@ recv(char *msg, int msglen)
{
int rval;
if (_msgsock == -1 && accept() == -1) {
if (_msgsock == -1 || accept() == -1) {
return(-1);
}

View file

@ -271,6 +271,7 @@ ttdt_session_join(
if (join) {
status = tt_session_join( sessid );
if (status != TT_OK) {
free(pats);
return (Tt_pattern *)tt_error_pointer( status );
}
}

View file

@ -533,6 +533,7 @@ entry(const char *argskey, _Tt_entry_pt func, ...)
_tt_syslog(0, LOG_ERR,
"_Tt_audit::entry(): ARG_INTEGER: func==%s",
_tt_enumname(func));
va_end(ap);
return TT_ERR_INTERNAL;
}
} break;

View file

@ -76,7 +76,10 @@ _tt_log_error(int errno, int line, char *file, char *msg)
if (fl == (FILE *)0) {
return;
}
fcntl(fileno(fl), F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fileno(fl), F_SETFD, 1) == -1) {
return;
}
time(&clock);
timestamp = _XCtime(&clock, ctime_buf);

View file

@ -102,7 +102,7 @@ class _Tt_trace_stream;
class _Tt_trace : public _Tt_allocated {
public:
// suppresses "used but not set" warnings
_Tt_trace() {};
_Tt_trace() : _funcname(TT_X_SESSION), _tracing(0) {};
// Initializes tracing (if necessary)
static int init(
int even_if_no_envariable = 0

View file

@ -649,6 +649,11 @@ _create_datfile(isfname)
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
if (fd > -1) {
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fd, F_SETFD, 1) == -1) {
close(fd);
return(-1);
}
}
return (fd);
}
@ -671,7 +676,11 @@ _create_indfile(isfname)
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
if (fd > -1) {
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fd, F_SETFD, 1) == -1) {
close(fd);
return(-1);
}
}
return (fd);
}
@ -694,7 +703,11 @@ _create_varfile(isfname)
fd = open (namebuf, O_CREAT | O_EXCL | O_RDWR, 0666);
if (fd > -1) {
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fd, F_SETFD, 1) == -1) {
close(fd);
return(-1);
}
}
return (fd);
}
@ -774,14 +787,22 @@ _open_datfile(isfname, rdonly)
if ((ret = open (namebuf, O_RDWR)) != -1) {
*rdonly = FALSE;
fcntl(ret, F_SETFD, 1); /* Close on exec */
return (ret);
/* Close on exec */
if(fcntl(ret, F_SETFD, 1) == -1) {
close(ret);
ret = -1;
}
return (ret);
}
*rdonly = TRUE;
ret = open (namebuf, O_RDONLY);
if (ret > -1) {
fcntl(ret, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(ret, F_SETFD, 1) == -1) {
close(ret);
return(-1);
}
}
return (ret);
}
@ -805,7 +826,11 @@ _open_indfile(isfname, rdonly)
fd = open (namebuf, (rdonly==TRUE)?O_RDONLY:O_RDWR);
if (fd > -1) {
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fd, F_SETFD, 1) == -1) {
close(fd);
return(-1);
}
}
return (fd);
}
@ -829,7 +854,11 @@ _open_varfile(isfname, rdonly)
fd = open (namebuf, (rdonly==TRUE)?O_RDONLY:O_RDWR);
if (fd > -1) {
fcntl(fd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fd, F_SETFD, 1) == -1) {
close(fd);
return(-1);
}
}
return (fd);
}
@ -882,7 +911,11 @@ _open2_indfile(fcb)
fcb->indfd = open(namebuf, openmode, buf.st_mode);
if (fcb->indfd > -1) {
fcntl(fcb->indfd, F_SETFD, 1); /* Close on exec */
/* Close on exec */
if(fcntl(fcb->indfd, F_SETFD, 1) == -1) {
close(fcb->indfd);
fcb->indfd = -1;
}
}
if(fcb->indfd == -1 && (openmode & O_CREAT)) {

View file

@ -112,21 +112,30 @@ isrepair(isfname, verbose)
_makedat_isfname(namebuf);
datfd = open(namebuf, O_RDONLY);
if (datfd > -1) {
fcntl(datfd, F_SETFD, 1);
if(fcntl(datfd, F_SETFD, 1) == -1) {
close(datfd);
datfd = -1;
}
}
(void)strcpy(namebuf, isfname);
_makeind_isfname(namebuf);
indfd = open(namebuf, O_RDONLY);
if (indfd > -1) {
fcntl(indfd, F_SETFD, 1);
if(fcntl(indfd, F_SETFD, 1) == -1) {
close(indfd);
indfd = -1;
}
}
(void)strcpy(namebuf, isfname);
_makevar_isfname(namebuf);
varfd = open(namebuf, O_RDONLY);
if (varfd > -1) {
fcntl(varfd, F_SETFD, 1);
if(fcntl(varfd, F_SETFD, 1) == -1) {
close(varfd);
varfd = -1;
}
}
(void)print("Reading control page from %s.rec file...\n",

View file

@ -391,7 +391,10 @@ gettransient(int proto, int vers, int *sockp)
addr.sin_port = htons(0);
addr.sin_family = AF_INET;
len = sizeof(addr);
bind(s, (sockaddr *)&addr, len);
if(bind(s, (sockaddr *)&addr, len) == -1) {
_tt_syslog(0, LOG_ERR, "bind(): %m");
return(0);
}
#if defined (_AIX) && (OSMAJORVERSION==4) && (OSMINORVERSION==2)
if (getsockname(s, (sockaddr *)&addr, (size_t *)&len) < 0) {
#else