diff --git a/.github/workflows/OpenAvnu_Build.yml b/.github/workflows/OpenAvnu_Build.yml new file mode 100644 index 0000000000..27987c34d0 --- /dev/null +++ b/.github/workflows/OpenAvnu_Build.yml @@ -0,0 +1,100 @@ +name: OpenAvnu Build CI + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: false # wir setzen die URLs gleich manuell + + - name: Set up dependencies + run: | + sudo apt update + sudo apt install -y \ + git build-essential cmake g++ \ + libpcap-dev libnl-3-dev libnl-genl-3-dev \ + uuid-dev libavahi-client-dev \ + linux-headers-generic libglib2.0-dev \ + libpci-dev libsndfile1-dev libjack-dev \ + libasound2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev + + - name: Fix submodule URLs + run: | + git config --file .gitmodules submodule.avdecc-lib.url https://github.com/AVnu/avdecc-lib.git + git config --file .gitmodules submodule.lib/atl_avb.url https://github.com/zarfld/atl_avb.git + git config --file .gitmodules submodule.lib/igb_avb.url https://github.com/AVnu/igb_avb.git + git config --file .gitmodules submodule.thirdparty/cpputest.url https://github.com/cpputest/cpputest.git + git submodule sync + git submodule update --init --recursive + + - name: Build daemons/maap seperately + run: | + make -C daemons/maap + continue-on-error: true + + - name: Build daemons/mrpd seperately + run: | + make -C daemons/mrpd + continue-on-error: true + + - name: Build daemons/shaper seperately + run: | + make -C daemons/shaper + continue-on-error: true + + - name: Build examples/simple_listener seperately + run: | + make -C examples/simple_listener + continue-on-error: true + + - name: Build examples/simple_talker seperately + run: | + make -C examples/simple_talker + continue-on-error: true + + - name: Build all + run: | + make all + + - name: Build lib/igb_avb/lib + run: | + make -C lib/igb_avb/lib all + + # ─────────────────────────────────────────────────────────────── + # Fehlerbehandlung: nur ausführen, wenn obiger Build fehlschlägt + # ─────────────────────────────────────────────────────────────── + + - name: Print directory contents on failure + if: failure() + run: | + echo "::group::Directory structure" + find . -type f | sort + echo "::endgroup::" + + - name: Show last 100 lines of all *.log or *.txt + if: failure() + run: | + find . -type f \( -name "*.log" -o -name "*.txt" \) -exec echo "::group::{}" \; -exec tail -n 100 {} \; -exec echo "::endgroup::" \; + + - name: Upload build output (if any) + if: failure() + uses: actions/upload-artifact@v4 + with: + name: build-output-on-failure + path: | + lib/**/lib*.a + **/*.o + **/*.log + **/*.txt diff --git a/.github/workflows/travis_sh.yml b/.github/workflows/travis_sh.yml new file mode 100644 index 0000000000..5fd2c19e78 --- /dev/null +++ b/.github/workflows/travis_sh.yml @@ -0,0 +1,89 @@ +name: Build and Test + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential cmake + + - name: Set up dependencies + run: | + sudo apt update + sudo apt install -y \ + git build-essential cmake g++ \ + libpcap-dev libnl-3-dev libnl-genl-3-dev \ + uuid-dev libavahi-client-dev \ + linux-headers-generic libglib2.0-dev \ + libpci-dev libsndfile1-dev libjack-dev \ + libasound2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev + + - name: Fix submodule URLs + run: | + git config --file .gitmodules submodule.avdecc-lib.url https://github.com/AVnu/avdecc-lib.git + git config --file .gitmodules submodule.lib/atl_avb.url https://github.com/zarfld/atl_avb.git + git config --file .gitmodules submodule.lib/igb_avb.url https://github.com/AVnu/igb_avb.git + git config --file .gitmodules submodule.thirdparty/cpputest.url https://github.com/cpputest/cpputest.git + git submodule sync + git submodule update --init --recursive + + - name: Run legacy make tasks + run: | + set -ev + make daemons_all + make examples_all + make avtp_pipeline + + - name: Run legacy make avdecc + run: | + make avtp_avdecc + continue-on-error: true + + - name: Update to latest CppUTest + run: | + cd thirdparty/cpputest + git checkout master + git pull origin master + + - name: Configure and build CppUTest + run: | + mkdir -p cpputest_build + cd cpputest_build + cmake ../thirdparty/cpputest \ + -DCPPUTEST_USE_STD_CPP_LIB=ON \ + -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/cpputest_install + make + make install + + - name: Configure CMake project + run: | + mkdir build + cd build + cmake .. -G "Unix Makefiles" \ + -DCMAKE_CXX_FLAGS="-fexceptions -funwind-tables" \ + -DCMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/cpputest_install + + - name: Build project + run: | + cd build + make + + - name: Run tests + run: | + cd build + ARGS=--output-on-failure make test diff --git a/README.rst b/README.rst index 9ab93af780..6ddaf19089 100644 --- a/README.rst +++ b/README.rst @@ -2,9 +2,10 @@ .. image:: avnu_logo.png | +.. image:: https://github.com/zarfld/OpenAvnu/actions/workflows/travis_sh.yml/badge.svg?branch=open-avb-next + :target: https://github.com/zarfld/OpenAvnu/actions/workflows/travis_sh.yml + :alt: Build status -.. image:: https://travis-ci.org/AVnu/OpenAvnu.svg?branch=open-avb-next - :target: https://travis-ci.org/AVnu/OpenAvnu OpenAvnu ======== diff --git a/daemons/maap/common/maap_log.h b/daemons/maap/common/maap_log.h index eb9ca01f25..c71c56d78f 100644 --- a/daemons/maap/common/maap_log.h +++ b/daemons/maap/common/maap_log.h @@ -85,7 +85,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define LOG_MSG_LEN 1024 // The length of the full message -#define LOG_FULL_MSG_LEN 1024 +#define LOG_FULL_MSG_LEN 2048 #ifndef TRUE #define TRUE 1 @@ -135,7 +135,7 @@ static const int MAAP_LOG_FROM_THREAD = TRUE; static const int MAAP_LOG_PULL_MODE = FALSE; // When using the MAAP_LOG_FROM_THREAD option. These defines control the behavior of the msg queue -#define LOG_QUEUE_MSG_LEN 256 +#define LOG_QUEUE_MSG_LEN 2048 #define LOG_QUEUE_MSG_SIZE (LOG_QUEUE_MSG_LEN + 1) #define LOG_QUEUE_MSG_CNT 82 #define LOG_QUEUE_SLEEP_MSEC 100 diff --git a/daemons/maap/linux/src/maap_log_linux.c b/daemons/maap/linux/src/maap_log_linux.c index 35dcfcbc30..bf10092701 100644 --- a/daemons/maap/linux/src/maap_log_linux.c +++ b/daemons/maap/linux/src/maap_log_linux.c @@ -104,35 +104,35 @@ void maapLogRTRender(log_queue_item_t *pLogItem) strcat((char *)pLogItem->msg, pLogRTItem->pFormat); break; case LOG_RT_DATATYPE_NOW_TS: - sprintf(rt_msg, "[%lu:%09lu] ", pLogRTItem->data.nowTS.tv_sec, pLogRTItem->data.nowTS.tv_nsec); + snprintf(rt_msg, sizeof(rt_msg), "[%lu:%09lu] ", pLogRTItem->data.nowTS.tv_sec, pLogRTItem->data.nowTS.tv_nsec); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_U16: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedShortVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedShortVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_S16: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedShortVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedShortVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_U32: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedLongVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedLongVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_S32: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedLongVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedLongVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_U64: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedLongLongVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedLongLongVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_S64: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedLongLongVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedLongLongVar); strcat((char *)pLogItem->msg, rt_msg); break; case LOG_RT_DATATYPE_FLOAT: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.floatVar); + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.floatVar); strcat((char *)pLogItem->msg, rt_msg); break; default: @@ -250,7 +250,7 @@ void maapLogFn( LOG_LOCK(); - vsprintf(msg, fmt, args); + vsnprintf(msg, sizeof(msg), fmt, args); if (MAAP_LOG_FILE_INFO && path) { char* file = strrchr(path, '/'); @@ -260,33 +260,33 @@ void maapLogFn( file += 1; else file = (char*)path; - sprintf(file_msg, " %s:%d", file, line); + snprintf(file_msg, sizeof(file_msg), " %s:%d", file, line); } if (MAAP_LOG_PROC_INFO) { - sprintf(proc_msg, " P:%5.5d", GET_PID()); + snprintf(proc_msg, sizeof(proc_msg), " P:%5.5d", GET_PID()); } if (MAAP_LOG_THREAD_INFO) { - sprintf(thread_msg, " T:%lu", THREAD_SELF()); + snprintf(thread_msg, sizeof(thread_msg), " T:%lu", THREAD_SELF()); } if (MAAP_LOG_TIME_INFO) { time_t tNow = time(NULL); struct tm tmNow; localtime_r(&tNow, &tmNow); - sprintf(time_msg, "%2.2d:%2.2d:%2.2d", tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec); + snprintf(time_msg, sizeof(time_msg), "%2.2d:%2.2d:%2.2d", tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec); } if (MAAP_LOG_TIMESTAMP_INFO) { struct timespec nowTS; clock_gettime(CLOCK_REALTIME, &nowTS); - sprintf(timestamp_msg, "%lu:%09lu", nowTS.tv_sec, nowTS.tv_nsec); + snprintf(timestamp_msg, sizeof(timestamp_msg), "%lu:%09lu", nowTS.tv_sec, nowTS.tv_nsec); } // using sprintf and puts allows using static buffers rather than heap. - if (MAAP_LOG_EXTRA_NEWLINE) - /* int32_t full_msg_len = */ sprintf(full_msg, "[%s%s%s%s %s %s%s] %s: %s\n", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); - else - /* int32_t full_msg_len = */ sprintf(full_msg, "[%s%s%s%s %s %s%s] %s: %s", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); + if (MAAP_LOG_EXTRA_NEWLINE) + /* int32_t full_msg_len = */ snprintf(full_msg, sizeof(full_msg), "[%s%s%s%s %s %s%s] %s: %s\n", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); + else + /* int32_t full_msg_len = */ snprintf(full_msg, sizeof(full_msg), "[%s%s%s%s %s %s%s] %s: %s", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); if (!MAAP_LOG_FROM_THREAD && !MAAP_LOG_PULL_MODE) { fputs(full_msg, MAAP_LOG_OUTPUT_FD); @@ -297,8 +297,8 @@ void maapLogFn( if (elem) { log_queue_item_t *pLogItem = (log_queue_item_t *)maapLogQueueData(elem); pLogItem->bRT = FALSE; - strncpy((char *)pLogItem->msg, full_msg, LOG_QUEUE_MSG_LEN); - maapLogQueueHeadPush(logQueue); + snprintf((char *)pLogItem->msg, LOG_QUEUE_MSG_SIZE, "%s", full_msg); + maapLogQueueHeadPush(logQueue); } } } diff --git a/daemons/maap/test/maap_test.c b/daemons/maap/test/maap_test.c index 28f11daae2..6e4ac25703 100644 --- a/daemons/maap/test/maap_test.c +++ b/daemons/maap/test/maap_test.c @@ -232,16 +232,18 @@ int main(int argc, char *argv[]) { bpf_u_int32 mask; bpf_u_int32 net; - if (argc < 2) { - dev = pcap_lookupdev(errbuf); - if (dev == NULL) { - fprintf(stderr, "Couldn't find default device: %s\n", errbuf); - fprintf(stderr, "Try specifying the device you want: %s \n", argv[0]); - return 2; - } - } else { - dev = argv[1]; - } + if (argc < 2) { + pcap_if_t *alldevs; + if (pcap_findalldevs(&alldevs, errbuf) == -1 || alldevs == NULL) { + fprintf(stderr, "Couldn't find default device: %s\n", errbuf); + fprintf(stderr, "Try specifying the device you want: %s \n", argv[0]); + return 2; + } + dev = alldevs->name; + pcap_freealldevs(alldevs); + } else { + dev = argv[1]; + } if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) { fprintf(stderr, "Couldn't get netmask for device: %s\n", dev); diff --git a/daemons/mrpd/mmrp.c b/daemons/mrpd/mmrp.c index 15fba7f037..4631cbe90d 100644 --- a/daemons/mrpd/mmrp.c +++ b/daemons/mrpd/mmrp.c @@ -1428,23 +1428,23 @@ int mmrp_send_notifications(struct mmrp_attribute *attrib, int notify) memset(msgbuf, 0, MAX_MRPD_CMDSZ); if (MMRP_SVCREQ_TYPE == attrib->type) { - sprintf(variant, "S=%d", attrib->attribute.svcreq); + snprintf(variant, 128, "S=%d", attrib->attribute.svcreq); } else { - sprintf(variant, "M=%02x%02x%02x%02x%02x%02x", - attrib->attribute.macaddr[0], - attrib->attribute.macaddr[1], - attrib->attribute.macaddr[2], - attrib->attribute.macaddr[3], - attrib->attribute.macaddr[4], - attrib->attribute.macaddr[5]); + snprintf(variant, 128, "M=%02x%02x%02x%02x%02x%02x", + attrib->attribute.macaddr[0], + attrib->attribute.macaddr[1], + attrib->attribute.macaddr[2], + attrib->attribute.macaddr[3], + attrib->attribute.macaddr[4], + attrib->attribute.macaddr[5]); } - sprintf(regsrc, "R=%02x%02x%02x%02x%02x%02x", - attrib->registrar.macaddr[0], - attrib->registrar.macaddr[1], - attrib->registrar.macaddr[2], - attrib->registrar.macaddr[3], - attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); + snprintf(regsrc, 128, "R=%02x%02x%02x%02x%02x%02x", + attrib->registrar.macaddr[0], + attrib->registrar.macaddr[1], + attrib->registrar.macaddr[2], + attrib->registrar.macaddr[3], + attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); mrp_decode_state(&attrib->registrar, &attrib->applicant, mrp_state, sizeof(mrp_state)); @@ -1508,43 +1508,45 @@ int mmrp_dumptable(struct sockaddr_in *client) attrib = MMRP_db->attrib_list; if (attrib == NULL) { - sprintf(msgbuf, "MMRP:Empty\n"); + snprintf(msgbuf, MAX_MRPD_CMDSZ, "MMRP:Empty\n"); } while (NULL != attrib) { if (MMRP_SVCREQ_TYPE == attrib->type) { - sprintf(variant, "S=%d", attrib->attribute.svcreq); + snprintf(variant, 128, "S=%d", attrib->attribute.svcreq); } else { - sprintf(variant, "M=%02x%02x%02x%02x%02x%02x", - attrib->attribute.macaddr[0], - attrib->attribute.macaddr[1], - attrib->attribute.macaddr[2], - attrib->attribute.macaddr[3], - attrib->attribute.macaddr[4], - attrib->attribute.macaddr[5]); + snprintf(variant, 128, "M=%02x%02x%02x%02x%02x%02x", + attrib->attribute.macaddr[0], + attrib->attribute.macaddr[1], + attrib->attribute.macaddr[2], + attrib->attribute.macaddr[3], + attrib->attribute.macaddr[4], + attrib->attribute.macaddr[5]); } - sprintf(regsrc, "R=%02x%02x%02x%02x%02x%02x", - attrib->registrar.macaddr[0], - attrib->registrar.macaddr[1], - attrib->registrar.macaddr[2], - attrib->registrar.macaddr[3], - attrib->registrar.macaddr[4], - attrib->registrar.macaddr[5]); + snprintf(regsrc, 128, "R=%02x%02x%02x%02x%02x%02x", + attrib->registrar.macaddr[0], + attrib->registrar.macaddr[1], + attrib->registrar.macaddr[2], + attrib->registrar.macaddr[3], + attrib->registrar.macaddr[4], + attrib->registrar.macaddr[5]); switch (attrib->registrar.mrp_state) { case MRP_IN_STATE: - sprintf(stage, "MIN %s %s\n", variant, regsrc); + snprintf(stage, 128, "MIN %s %s\n", variant, regsrc); break; case MRP_LV_STATE: - sprintf(stage, "MLV %s %s\n", variant, regsrc); + snprintf(stage, 128, "MLV %s %s\n", variant, regsrc); break; case MRP_MT_STATE: - sprintf(stage, "MMT %s %s\n", variant, regsrc); + snprintf(stage, 128, "MMT %s %s\n", variant, regsrc); break; default: break; } - sprintf(msgbuf_wrptr, "%s", stage); - msgbuf_wrptr += strnlen(stage, 128); + snprintf(msgbuf_wrptr, + MAX_MRPD_CMDSZ - (msgbuf_wrptr - msgbuf), + "%s", stage); + msgbuf_wrptr += strnlen(stage, 128); attrib = attrib->next; } @@ -1615,7 +1617,7 @@ int mmrp_recv_cmd(char *buf, int buflen, struct sockaddr_in *client) { int rc; int err_index; - char respbuf[12]; + char respbuf[64]; int mrp_event; uint8_t svcreq_param; uint8_t macvec_param[6]; diff --git a/daemons/mrpd/mrpd.c b/daemons/mrpd/mrpd.c index a712e2da6a..eaac09b6e0 100644 --- a/daemons/mrpd/mrpd.c +++ b/daemons/mrpd/mrpd.c @@ -258,8 +258,7 @@ mrpd_send_ctl_msg(struct sockaddr_in *client_addr, char *notify_data, int process_ctl_msg(char *buf, int buflen, struct sockaddr_in *client) { - - char respbuf[8]; + char respbuf[64]; /* * Inbound/output commands from/to a client: * diff --git a/daemons/mrpd/mrpd.h b/daemons/mrpd/mrpd.h index d33de12924..e6f69f0f25 100644 --- a/daemons/mrpd/mrpd.h +++ b/daemons/mrpd/mrpd.h @@ -47,7 +47,9 @@ size_t mrpd_send(SOCKET sockfd, const void *buf, size_t len, int flags); #include #include #include +#ifndef SOCKET typedef int SOCKET; +#endif typedef int HTIMER; #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 diff --git a/daemons/mrpd/mvrp.c b/daemons/mrpd/mvrp.c index fa14ac378a..b26d0e9420 100644 --- a/daemons/mrpd/mvrp.c +++ b/daemons/mrpd/mvrp.c @@ -1033,14 +1033,14 @@ int mvrp_send_notifications(struct mvrp_attribute *attrib, int notify) memset(msgbuf, 0, MAX_MRPD_CMDSZ); - sprintf(variant, "%04x", attrib->attribute); + snprintf(variant, 128, "%04x", attrib->attribute); - sprintf(regsrc, "R=%02x%02x%02x%02x%02x%02x", - attrib->registrar.macaddr[0], - attrib->registrar.macaddr[1], - attrib->registrar.macaddr[2], - attrib->registrar.macaddr[3], - attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); + snprintf(regsrc, 128, "R=%02x%02x%02x%02x%02x%02x", + attrib->registrar.macaddr[0], + attrib->registrar.macaddr[1], + attrib->registrar.macaddr[2], + attrib->registrar.macaddr[3], + attrib->registrar.macaddr[4], attrib->registrar.macaddr[5]); mrp_decode_state(&attrib->registrar, &attrib->applicant, mrp_state, sizeof(mrp_state)); @@ -1105,25 +1105,27 @@ int mvrp_dumptable(struct sockaddr_in *client) attrib = MVRP_db->attrib_list; if (attrib == NULL) { - sprintf(msgbuf, "MVRP:Empty\n"); + snprintf(msgbuf, MAX_MRPD_CMDSZ, "MVRP:Empty\n"); } while (NULL != attrib) { - sprintf(variant, "V:I=%04x", attrib->attribute); + snprintf(variant, 128, "V:I=%04x", attrib->attribute); mrp_decode_state(&attrib->registrar, &attrib->applicant, mrp_state, sizeof(mrp_state)); - sprintf(regsrc, "R=%02x%02x%02x%02x%02x%02x %s", - attrib->registrar.macaddr[0], - attrib->registrar.macaddr[1], - attrib->registrar.macaddr[2], - attrib->registrar.macaddr[3], - attrib->registrar.macaddr[4], - attrib->registrar.macaddr[5], mrp_state); - - sprintf(stage, "%s %s\n", variant, regsrc); - sprintf(msgbuf_wrptr, "%s", stage); + snprintf(regsrc, 128, "R=%02x%02x%02x%02x%02x%02x %s", + attrib->registrar.macaddr[0], + attrib->registrar.macaddr[1], + attrib->registrar.macaddr[2], + attrib->registrar.macaddr[3], + attrib->registrar.macaddr[4], + attrib->registrar.macaddr[5], mrp_state); + + snprintf(stage, 128, "%s %s\n", variant, regsrc); + snprintf(msgbuf_wrptr, + MAX_MRPD_CMDSZ - (msgbuf_wrptr - msgbuf), + "%s", stage); msgbuf_wrptr += strnlen(stage, 128); attrib = attrib->next; } @@ -1173,7 +1175,7 @@ int mvrp_recv_cmd(char *buf, int buflen, struct sockaddr_in *client) { int rc; int mrp_event; - char respbuf[12]; + char respbuf[64]; uint16_t vid_param; int err_index; diff --git a/daemons/shaper/src/shaper_daemon.c b/daemons/shaper/src/shaper_daemon.c index 1ef6a69c18..00e6587b70 100644 --- a/daemons/shaper/src/shaper_daemon.c +++ b/daemons/shaper/src/shaper_daemon.c @@ -470,14 +470,14 @@ int process_command(int sockfd, char command[]) return -1; } } - if (input.unreserve_bw) - { - if (input.stream_da == 0) - { - log_client_error_message(sockfd, "Stream Destination Address is required to unreserve bandwidth"); - usage(sockfd); - return -1; - } + if (input.unreserve_bw) + { + if (strlen(input.stream_da) == 0) + { + log_client_error_message(sockfd, "Stream Destination Address is required to unreserve bandwidth"); + usage(sockfd); + return -1; + } } if ((input.quit==1 || input.delete_qdisc==1) &&(input.reserve_bw==1 || input.unreserve_bw==1)) { diff --git a/daemons/shaper/src/shaper_log_linux.c b/daemons/shaper/src/shaper_log_linux.c index 38017c389f..728db55ba3 100644 --- a/daemons/shaper/src/shaper_log_linux.c +++ b/daemons/shaper/src/shaper_log_linux.c @@ -60,7 +60,7 @@ typedef struct { static shaper_log_queue_t logQueue; static shaper_log_queue_t logRTQueue; -static char msg[LOG_MSG_LEN] = ""; +static char msg[LOG_QUEUE_MSG_LEN] = ""; static char time_msg[LOG_TIME_LEN] = ""; static char timestamp_msg[LOG_TIMESTAMP_LEN] = ""; static char file_msg[LOG_FILE_LEN] = ""; @@ -102,38 +102,38 @@ void shaperLogRTRender(log_queue_item_t *pLogItem) case LOG_RT_DATATYPE_CONST_STR: strcat((char *)pLogItem->msg, pLogRTItem->pFormat); break; - case LOG_RT_DATATYPE_NOW_TS: - sprintf(rt_msg, "[%lu:%09lu] ", pLogRTItem->data.nowTS.tv_sec, pLogRTItem->data.nowTS.tv_nsec); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_U16: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedShortVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_S16: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedShortVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_U32: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedLongVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_S32: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedLongVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_U64: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.unsignedLongLongVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_S64: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.signedLongLongVar); - strcat((char *)pLogItem->msg, rt_msg); - break; - case LOG_RT_DATATYPE_FLOAT: - sprintf(rt_msg, pLogRTItem->pFormat, pLogRTItem->data.floatVar); - strcat((char *)pLogItem->msg, rt_msg); - break; + case LOG_RT_DATATYPE_NOW_TS: + snprintf(rt_msg, sizeof(rt_msg), "[%lu:%09lu] ", pLogRTItem->data.nowTS.tv_sec, pLogRTItem->data.nowTS.tv_nsec); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_U16: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedShortVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_S16: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedShortVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_U32: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedLongVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_S32: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedLongVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_U64: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.unsignedLongLongVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_S64: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.signedLongLongVar); + strcat((char *)pLogItem->msg, rt_msg); + break; + case LOG_RT_DATATYPE_FLOAT: + snprintf(rt_msg, sizeof(rt_msg), pLogRTItem->pFormat, pLogRTItem->data.floatVar); + strcat((char *)pLogItem->msg, rt_msg); + break; default: break; } @@ -250,12 +250,12 @@ void shaperLogFn( ...) { if (level <= SHAPER_LOG_LEVEL) { - va_list args; - va_start(args, fmt); + va_list args; + va_start(args, fmt); - LOG_LOCK(); + LOG_LOCK(); - vsprintf(msg, fmt, args); + vsnprintf(msg, sizeof(msg), fmt, args); if (SHAPER_LOG_FILE_INFO && path) { char* file = strrchr(path, '/'); @@ -265,33 +265,33 @@ void shaperLogFn( file += 1; else file = (char*)path; - sprintf(file_msg, " %s:%d", file, line); + snprintf(file_msg, sizeof(file_msg), " %s:%d", file, line); } if (SHAPER_LOG_PROC_INFO) { - sprintf(proc_msg, " P:%5.5d", GET_PID()); + snprintf(proc_msg, sizeof(proc_msg), " P:%5.5d", GET_PID()); } if (SHAPER_LOG_THREAD_INFO) { - sprintf(thread_msg, " T:%lu", THREAD_SELF()); + snprintf(thread_msg, sizeof(thread_msg), " T:%lu", THREAD_SELF()); } if (SHAPER_LOG_TIME_INFO) { time_t tNow = time(NULL); struct tm tmNow; localtime_r(&tNow, &tmNow); - sprintf(time_msg, "%2.2d:%2.2d:%2.2d", tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec); + snprintf(time_msg, sizeof(time_msg), "%2.2d:%2.2d:%2.2d", tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec); } if (SHAPER_LOG_TIMESTAMP_INFO) { struct timespec nowTS; clock_gettime(CLOCK_REALTIME, &nowTS); - sprintf(timestamp_msg, "%lu:%09lu", nowTS.tv_sec, nowTS.tv_nsec); + snprintf(timestamp_msg, sizeof(timestamp_msg), "%lu:%09lu", nowTS.tv_sec, nowTS.tv_nsec); } // using sprintf and puts allows using static buffers rather than heap. - if (SHAPER_LOG_EXTRA_NEWLINE) - /* int32_t full_msg_len = */ sprintf(full_msg, "[%s%s%s%s %s %s%s] %s: %s\n", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); - else - /* int32_t full_msg_len = */ sprintf(full_msg, "[%s%s%s%s %s %s%s] %s: %s", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); + if (SHAPER_LOG_EXTRA_NEWLINE) + /* int32_t full_msg_len = */ snprintf(full_msg, sizeof(full_msg), "[%s%s%s%s %s %s%s] %s: %s\n", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); + else + /* int32_t full_msg_len = */ snprintf(full_msg, sizeof(full_msg), "[%s%s%s%s %s %s%s] %s: %s", time_msg, timestamp_msg, proc_msg, thread_msg, company, component, file_msg, tag, msg); if (!SHAPER_LOG_FROM_THREAD && !SHAPER_LOG_PULL_MODE) { fputs(full_msg, SHAPER_LOG_OUTPUT_FD); @@ -302,7 +302,12 @@ void shaperLogFn( if (elem) { log_queue_item_t *pLogItem = (log_queue_item_t *)shaperLogQueueData(elem); pLogItem->bRT = FALSE; - strncpy((char *)pLogItem->msg, full_msg, LOG_QUEUE_MSG_LEN); + size_t len = strlen(full_msg); + if (len >= LOG_QUEUE_MSG_LEN) { + len = LOG_QUEUE_MSG_LEN - 1; + } + memcpy(pLogItem->msg, full_msg, len); + pLogItem->msg[len] = '\0'; shaperLogQueueHeadPush(logQueue); } } @@ -428,11 +433,11 @@ void shaperLogBuffer( pszOut = szDataLine; *pszOut++ = '\t'; for (j = i; j < i + lineLen; ++j) { - if (j < dataLen) { - sprintf(pszOut, "%02x ", pData[j]); - } else { - strcpy(pszOut, " "); - } + if (j < dataLen) { + snprintf(pszOut, 4, "%02x ", pData[j]); + } else { + strcpy(pszOut, " "); + } pszOut += 3; } diff --git a/examples/common/talker_mrp_client.c b/examples/common/talker_mrp_client.c index 6959e220be..f23c463b8c 100644 --- a/examples/common/talker_mrp_client.c +++ b/examples/common/talker_mrp_client.c @@ -271,13 +271,16 @@ int process_mrp_msg(char *buf, int buflen, struct mrp_talker_ctx *ctx) printf("listener left\n"); } break; - case 'J': - case 'N': - printf("got a new/join indication\n"); - if (substate > MSRP_LISTENER_ASKFAILED) { - if (memcmp - (recovered_streamid, - ctx->monitor_stream_id, + case 'J': + /* fall through */ + printf("fall through\n"); + break; + case 'N': + printf("got a new/join indication\n"); + if (substate > MSRP_LISTENER_ASKFAILED) { + if (memcmp + (recovered_streamid, + ctx->monitor_stream_id, sizeof(recovered_streamid)) == 0) ctx->listeners = 1; } diff --git a/lib/avtp_pipeline/platform/Linux/openavb_grandmaster_osal.c b/lib/avtp_pipeline/platform/Linux/openavb_grandmaster_osal.c index 7acbf76d5f..5ab277e6b1 100644 --- a/lib/avtp_pipeline/platform/Linux/openavb_grandmaster_osal.c +++ b/lib/avtp_pipeline/platform/Linux/openavb_grandmaster_osal.c @@ -51,7 +51,7 @@ static pthread_mutex_t gOSALGrandmasterInitMutex = PTHREAD_MUTEX_INITIALIZER; static bool bInitialized = FALSE; static int gShmFd = -1; static char *gMmap = NULL; -gPtpTimeData gPtpTD; +static gPtpTimeData gPtpTD; static bool x_grandmasterInit(void) { AVB_TRACE_ENTRY(AVB_TRACE_GRANDMASTER); diff --git a/lib/avtp_pipeline/platform/Linux/openavb_tasks.h b/lib/avtp_pipeline/platform/Linux/openavb_tasks.h index 387fd985b3..c653f39e7f 100644 --- a/lib/avtp_pipeline/platform/Linux/openavb_tasks.h +++ b/lib/avtp_pipeline/platform/Linux/openavb_tasks.h @@ -34,12 +34,14 @@ Complete license and copyright information can be found at #include -#if !defined(PTHREAD_STACK_MIN) -#error "PTHREAD_STACK_MIN variable not defined" -#elif (PTHREAD_STACK_MIN > 65536) -#define THREAD_STACK_SIZE PTHREAD_STACK_MIN +#if defined(PTHREAD_STACK_MIN) && !defined(__USE_DYNAMIC_STACK_SIZE) +# if PTHREAD_STACK_MIN > 65536 +# define THREAD_STACK_SIZE PTHREAD_STACK_MIN +# else +# define THREAD_STACK_SIZE 65536 +# endif #else -#define THREAD_STACK_SIZE 65536 +# define THREAD_STACK_SIZE 65536 #endif /////////////////////////// diff --git a/lib/avtp_pipeline/platform/Linux/openavb_time_osal.c b/lib/avtp_pipeline/platform/Linux/openavb_time_osal.c index 9f2239b602..99c822e0bd 100644 --- a/lib/avtp_pipeline/platform/Linux/openavb_time_osal.c +++ b/lib/avtp_pipeline/platform/Linux/openavb_time_osal.c @@ -51,7 +51,7 @@ static pthread_mutex_t gOSALTimeInitMutex = PTHREAD_MUTEX_INITIALIZER; static bool bInitialized = FALSE; static int gPtpShmFd = -1; static char *gPtpMmap = NULL; -gPtpTimeData gPtpTD; +static gPtpTimeData gPtpTD; static bool x_timeInit(void) { AVB_TRACE_ENTRY(AVB_TRACE_TIME);