*
* \retval None, is added to destination char *newdevname
*/
-void LiveSafeDeviceName(const char *devname, char *newdevname)
+int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen)
{
size_t devnamelen = strlen(devname);
+ // If we have to shorten the interface name
if (devnamelen > MAX_DEVNAME) {
- strncpy(newdevname, devname, DEVNAME_CHUNCK);
- strncpy(newdevname+DEVNAME_CHUNCK, "...", 3);
- strncpy(newdevname+8, devname+(devnamelen-DEVNAME_CHUNCK), DEVNAME_CHUNCK);
- strncpy(newdevname+13, "\0", 1);
+
+ // We need 13 chars to do this shortening
+ if (destlen < 13) {
+ return 1;
+ }
+
+ size_t length;
+ length = strlcpy(newdevname, devname, DEVNAME_CHUNCK);
+ length = strlcat(newdevname, "...", DEVNAME_CHUNCK+3);
+ length = strlcat(newdevname, devname+(devnamelen-DEVNAME_CHUNCK), length+DEVNAME_CHUNCK);
SCLogInfo("Shortening device name to: %s", newdevname);
} else {
- strcpy(newdevname, devname);
+ strlcpy(newdevname, devname, destlen);
}
+ return 0;
}
/**
int LiveRegisterDevice(const char *dev);
int LiveGetDeviceCount(void);
char *LiveGetDeviceName(int number);
-void LiveSafeDeviceName(const char *devname, char *newdevname);
+int LiveSafeDeviceName(const char *devname, char *newdevname, size_t destlen);
LiveDevice *LiveGetDevice(const char *dev);
int LiveBuildDeviceList(const char *base);
void LiveDeviceHasNoStats(void);
for (lthread = 0; lthread < nlive; lthread++) {
char *live_dev = LiveGetDeviceName(lthread);
char visual_devname[14] = "";
+ int shortening_result;
void *aconf;
int threads_count;
threads_count = ModThreadsCount(aconf);
for (thread = 0; thread < threads_count; thread++) {
- LiveSafeDeviceName(live_dev, visual_devname);
+ shortening_result = LiveSafeDeviceName(live_dev, visual_devname, 13);
+ if (shortening_result != 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Could not shorten long devicename: %s", live_dev);
+ exit(EXIT_FAILURE);
+ }
+
snprintf(tname, sizeof(tname), "%s%s%d", thread_name,
live_dev, thread+1);
+
+ char *thread_name = SCStrdup(tname);
+ if (unlikely(thread_name == NULL)) {
+ SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate thread name");
+ exit(EXIT_FAILURE);
+ }
ThreadVars *tv_receive =
TmThreadCreatePacketHandler(tname,
"packetpool", "packetpool",
for (thread = 0; thread < threads_count; thread++) {
char tname[TM_THREAD_NAME_MAX];
char *n_thread_name = NULL;
- char visual_devname[13] = "";
+ char visual_devname[14] = "";
+ int shortening_result;
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
if (single_mode) {
snprintf(tname, sizeof(tname), "%s", thread_name);
} else {
- LiveSafeDeviceName(live_dev, visual_devname);
- SCLogInfo("New dev name %s", visual_devname);
+ shortening_result = LiveSafeDeviceName(live_dev, visual_devname, 13);
+ if (shortening_result != 0) {
+ SCLogError(SC_ERR_INVALID_VALUE, "Could not shorten long devicename: %s", live_dev);
+ exit(EXIT_FAILURE);
+ }
+
snprintf(tname, sizeof(tname), "%s%s%d",
thread_name, live_dev, thread+1);
}