diff options
author | Simon Brandner <simon.brandner@partner.bmw.de> | 2013-02-05 14:16:10 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-07-19 16:54:40 +0200 |
commit | 3bbfc218fd5053e95c6de274ef5a28ca80bcdee2 (patch) | |
tree | ff2ecd2ac569e8c2bbb3ac1cc0e5969025de7c9c | |
parent | e2943ff4cf2d7d2da4000e2ca35663a7c83675d7 (diff) | |
download | dlt-daemon-3bbfc218fd5053e95c6de274ef5a28ca80bcdee2.tar.gz dlt-daemon-3bbfc218fd5053e95c6de274ef5a28ca80bcdee2.tar.bz2 dlt-daemon-3bbfc218fd5053e95c6de274ef5a28ca80bcdee2.zip |
some coverity fixes
fixed some merge problems
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r-- | src/daemon/dlt_daemon_common.c | 12 | ||||
-rw-r--r-- | src/lib/dlt_filetransfer.c | 99 | ||||
-rwxr-xr-x | src/shared/dlt_common.c | 32 | ||||
-rw-r--r-- | src/system/dlt-system-filetransfer.c | 8 | ||||
-rwxr-xr-x | src/tests/dlt-test-client.c | 2 |
5 files changed, 112 insertions, 41 deletions
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index 1b34f21..afedff9 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -2288,12 +2288,18 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe /* Optional: Send serial header, if requested */ if (daemon->sendserialheader) { - send(sock, dltSerialHeader,sizeof(dltSerialHeader),0); + if (0 > send(sock, dltSerialHeader,sizeof(dltSerialHeader),0)) + dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send serialheader failed\n"); + } /* Send data */ - send(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),0); - send(sock, msg->databuffer,msg->datasize,0); + + if ( 0 > send(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),0)) + dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send DltStorageHeader failed\n"); + + if ( 0 > send(sock, msg->databuffer,msg->datasize,0)) + dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send databuffer failed\n"); DLT_DAEMON_SEM_FREE(); } diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index ce18f52..8ef0072 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -50,7 +50,10 @@ ** aw Alexander Wenzel BMW ** *******************************************************************************/ +#include <stdio.h> +#include <string.h> #include "dlt_filetransfer.h" +#include "dlt_common.h" //!Defines the buffer size of a single file package which will be logged to dlt #define BUFFER_SIZE 1024 @@ -69,11 +72,18 @@ unsigned char buffer[BUFFER_SIZE]; //!Get some information about the file size of a file /**See stat(2) for more informations. * @param file Absolute file path - * @return Returns the size of the file (if it is a regular file or a symbolic link) in bytes. + * @return Returns the size of the file (if it is a regular file or a symbolic link) in bytes. Returns 0 in case of error. Regard: can also be a size value! */ -unsigned long getFilesize(const char* file){ +unsigned long getFilesize(const char* file, int *ok){ struct stat st; - stat(file, &st); + + if ( -1 == stat(file, &st)) + { + //we can only return 0, as the value is unsigned + *ok = 0; + return 0; + } + *ok = 1; return (unsigned long)st.st_size; } @@ -106,15 +116,23 @@ void stringHash(const char* str, unsigned long *hash ) * @param file Absolute file path * @return Returns a unique number associated with each filename */ -unsigned long getFileSerialNumber(const char* file){ +unsigned long getFileSerialNumber(const char* file, int *ok){ struct stat st; unsigned long ret; - stat(file, &st); - ret = st.st_ino; - ret = ret << (sizeof(ret)*8)/2; - ret |= st.st_size; - ret ^= st.st_ctime; - stringHash(file, &ret); + if ( -1 == stat(file, &st)) + { + *ok = 0; + ret = 0; + } + else + { + *ok = 1; + ret = st.st_ino; + ret = ret << (sizeof(ret)*8)/2; + ret |= st.st_size; + ret ^= st.st_ctime; + stringHash(file, &ret); + } return ret; } @@ -191,13 +209,14 @@ void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filenam if(errno != ENOENT) { + int ok = 0; DLT_LOG(*fileContext,DLT_LOG_ERROR, DLT_STRING("FLER"), DLT_INT(errorCode), DLT_INT(-errno), - DLT_UINT(getFileSerialNumber(filename)), + DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_STRING(filename), - DLT_UINT(getFilesize(filename)), + DLT_UINT(getFilesize(filename,&ok)), DLT_STRING(getFileCreationDate2(filename)), DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), DLT_UINT(BUFFER_SIZE), @@ -226,11 +245,12 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename){ if(isFile(filename)) { + int ok; DLT_LOG(*fileContext,DLT_LOG_INFO, DLT_STRING("FLIF"), - DLT_STRING("file serialnumber"),DLT_UINT(getFileSerialNumber(filename)), + DLT_STRING("file serialnumber"),DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_STRING("filename"),DLT_STRING(filename), - DLT_STRING("file size in bytes"),DLT_UINT(getFilesize(filename)), + DLT_STRING("file size in bytes"),DLT_UINT(getFilesize(filename,&ok)), DLT_STRING("file creation date"),DLT_STRING(getFileCreationDate2(filename)), DLT_STRING("number of packages"),DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), DLT_STRING("FLIF") @@ -296,7 +316,12 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam if(isFile(filename)) { packages = 1; - filesize = getFilesize(filename); + int ok; + filesize = getFilesize(filename,&ok); + if (!ok){ + dlt_user_log_file_errorMessage(fileContext,filename,DLT_FILETRANSFER_ERROR_PACKAGE_COUNT); + return -1; + } if(filesize < BUFFER_SIZE) { return packages; @@ -334,15 +359,16 @@ int dlt_user_log_file_header_alias(DltContext *fileContext,const char *filename, if(isFile(filename)) { + int ok; DLT_LOG(*fileContext,DLT_LOG_INFO, - DLT_STRING("FLST"), - DLT_UINT(getFileSerialNumber(filename)), - DLT_STRING(alias), - DLT_UINT(getFilesize(filename)), - DLT_STRING(getFileCreationDate2(filename)); - DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), - DLT_UINT(BUFFER_SIZE), - DLT_STRING("FLST") + DLT_STRING("FLST"), + DLT_UINT(getFileSerialNumber(filename,&ok)), + DLT_STRING(alias), + DLT_UINT(getFilesize(filename,&ok)), + DLT_STRING(getFileCreationDate2(filename)); + DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), + DLT_UINT(BUFFER_SIZE), + DLT_STRING("FLST") ); return 0; @@ -367,11 +393,12 @@ int dlt_user_log_file_header(DltContext *fileContext,const char *filename){ if(isFile(filename)) { + int ok; DLT_LOG(*fileContext,DLT_LOG_INFO, DLT_STRING("FLST"), - DLT_UINT(getFileSerialNumber(filename)), + DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_STRING(filename), - DLT_UINT(getFilesize(filename)), + DLT_UINT(getFilesize(filename,&ok)), DLT_STRING(getFileCreationDate2(filename)); DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)), DLT_UINT(BUFFER_SIZE), @@ -433,12 +460,23 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac // if(checkUserBufferForFreeSpace()<0) // return DLT_FILETRANSFER_ERROR_FILE_DATA_USER_BUFFER_FAILED; - fseek ( file , (packageToTransfer-1)*BUFFER_SIZE , SEEK_SET ); + if ( 0 != fseek ( file , (packageToTransfer-1)*BUFFER_SIZE , SEEK_SET ) ) + { + DLT_LOG(*fileContext,DLT_LOG_ERROR, + DLT_STRING("failed to fseek in file: "), + DLT_STRING(filename), + DLT_STRING("ferror:"), + DLT_INT(ferror(file)) + ); + fclose (file); + return -1; + } readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); + int ok = 0; DLT_LOG(*fileContext,DLT_LOG_INFO, DLT_STRING("FLDA"), - DLT_UINT(getFileSerialNumber(filename)), + DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_UINT(packageToTransfer), DLT_RAW(buffer,readBytes), DLT_STRING("FLDA") @@ -456,10 +494,10 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac { pkgNumber++; readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); - + int ok; DLT_LOG(*fileContext,DLT_LOG_INFO, DLT_STRING("FLDA"), - DLT_UINT(getFileSerialNumber(filename)), + DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_UINT(pkgNumber), DLT_RAW(buffer,readBytes), DLT_STRING("FLDA") @@ -493,9 +531,10 @@ int dlt_user_log_file_end(DltContext *fileContext,const char *filename,int delet if(isFile(filename)) { + int ok; DLT_LOG(*fileContext,DLT_LOG_INFO, DLT_STRING("FLFI"), - DLT_UINT(getFileSerialNumber(filename)), + DLT_UINT(getFileSerialNumber(filename,&ok)), DLT_STRING("FLFI") ); diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index fbc1934..09a3258 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -1740,7 +1740,11 @@ int dlt_file_read(DltFile *file,int verbose) if (dlt_file_read_header_extended(file, verbose)<0) { /* go back to last position in file */ - fseek(file->handle,file->file_position,SEEK_SET); + if ( 0 != fseek(file->handle,file->file_position,SEEK_SET)) + { + sprintf(str,"Seek to last file pos failed!\n"); + dlt_log(LOG_ERR, str); + } return-1; } @@ -1760,9 +1764,15 @@ int dlt_file_read(DltFile *file,int verbose) if (fseek(file->handle,file->msg.datasize,SEEK_CUR)!=0) { /* go back to last position in file */ - fseek(file->handle,file->file_position,SEEK_SET); sprintf(str,"Seek failed to skip payload data of size %d!\n",file->msg.datasize); dlt_log(LOG_ERR, str); + + if (0 != fseek(file->handle,file->file_position,SEEK_SET)) + { + sprintf(str,"Seek back also failed!\n"); + dlt_log(LOG_ERR, str); + } + return -1; } } @@ -1844,7 +1854,11 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose) if (dlt_file_read_header_raw(file,resync,verbose)<0) { /* go back to last position in file */ - fseek(file->handle,file->file_position,SEEK_SET); + if (0!= fseek(file->handle,file->file_position,SEEK_SET)) + { + sprintf(str,"dlt_file_read_raw, fseek failed 1\n"); + dlt_log(LOG_ERR, str); + } return -1; } @@ -1852,14 +1866,22 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose) if (dlt_file_read_header_extended(file, verbose)<0) { /* go back to last position in file */ - fseek(file->handle,file->file_position,SEEK_SET); + if (0 != fseek(file->handle,file->file_position,SEEK_SET)) + { + sprintf(str,"dlt_file_read_raw, fseek failed 2\n"); + dlt_log(LOG_ERR, str); + } return-1; } if (dlt_file_read_data(file,verbose)<0) { /* go back to last position in file */ - fseek(file->handle,file->file_position,SEEK_SET); + if (0 != fseek(file->handle,file->file_position,SEEK_SET)) + { + sprintf(str,"dlt_file_read_raw, fseek failed 3\n"); + dlt_log(LOG_ERR, str); + } return-1; } diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c index a4b0aff..d33e6b9 100644 --- a/src/system/dlt-system-filetransfer.c +++ b/src/system/dlt-system-filetransfer.c @@ -67,7 +67,7 @@ extern DltSystemThreads threads; // From dlt_filetransfer -extern unsigned long getFileSerialNumber(const char* file); +extern unsigned long getFileSerialNumber(const char* file, int *ok); DLT_IMPORT_CONTEXT(dltsystem); DLT_DECLARE_CONTEXT(filetransferContext) @@ -96,7 +96,11 @@ char *unique_name(char *src) DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, creating unique temporary file name.")); time_t t = time(NULL); - unsigned long l = getFileSerialNumber(src) ^ t; + int ok; + unsigned long l = getFileSerialNumber(src, &ok) ^ t; + if (!ok){ + return (char*) NULL; + } char *basename_f = basename(src); // Length of ULONG_MAX + 1 diff --git a/src/tests/dlt-test-client.c b/src/tests/dlt-test-client.c index 3855000..5da480f 100755 --- a/src/tests/dlt-test-client.c +++ b/src/tests/dlt-test-client.c @@ -1827,7 +1827,7 @@ int dlt_testclient_message_callback(DltMessage *message, void *data) /* Get length */ DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t); length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); - if ((length==datalength) && (length=10)) + if ((length==datalength) && (length==10)) { dltdata->test_counter_function[1]++; } |