}
// must account for null terminator
if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
- strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
+ strncpy(fonts[font_count].name, data_in, text_buffer_size);
#ifdef XFT
fonts[font_count].font_alpha = 0xffff;
#endif
font_count++;
}
if (strlen(data_in) > 1) {
- strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE - 1);
+ strncpy(fonts[0].name, data_in, text_buffer_size);
#ifdef XFT
fonts[0].font_alpha = 0xffff;
#endif
static char *scan_font(const char *args)
{
if (args && *args) {
- return strdup(args);
+ return strndup(args, text_buffer_size);
}
return NULL;
}
if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
last_colour, scale) == 6) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
*scale = 0;
if (sscanf(args, "%63s %d,%d %x %x", buf, h, w, first_colour,
last_colour) == 5) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
buf[0] = '\0';
*h = 25;
}
if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
scale) == 4) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
*scale = 0;
if (sscanf(args, "%63s %x %x", buf, first_colour, last_colour) == 3) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
buf[0] = '\0';
*first_colour = 0;
sscanf(args, "%63s %d,%d", buf, h, w);
}
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
if (buf[0] == '\0') {
return NULL;
} else {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
}
} else {
strcpy(bat, "BAT0");
}
- obj->data.s = strdup(bat);
+ obj->data.s = strndup(bat, text_buffer_size);
END OBJ(battery_time, 0)
char bat[64];
} else {
strcpy(bat, "BAT0");
}
- obj->data.s = strdup(bat);
+ obj->data.s = strndup(bat, text_buffer_size);
END OBJ(battery_percent, 0)
char bat[64];
} else {
strcpy(bat, "BAT0");
}
- obj->data.s = strdup(bat);
+ obj->data.s = strndup(bat, text_buffer_size);
END OBJ(battery_bar, 0)
char bat[64];
obj->b = 6;
} else {
strcpy(bat, "BAT0");
}
- obj->data.s = strdup(bat);
+ obj->data.s = strndup(bat, text_buffer_size);
#endif /* !__OpenBSD__ */
#if defined(__linux__)
END OBJ(disk_protect, 0)
if (arg)
- obj->data.s = strdup(DEV_NAME(arg));
+ obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
else
CRIT_ERR("disk_protect needs an argument");
END OBJ(i8k_version, INFO_I8K)
ERR("if_up needs an argument");
obj->data.ifblock.s = 0;
} else
- obj->data.ifblock.s = strdup(arg);
+ obj->data.ifblock.s = strndup(arg, text_buffer_size);
blockstart[blockdepth] = object_count;
obj->data.ifblock.pos = object_count + 2;
blockdepth++;
CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
obj->data.s = 0;
} else
- obj->data.s = strdup(DEV_NAME(arg));
+ obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
END OBJ(laptop_mode, 0)
END OBJ(pb_battery, 0)
if (arg && strcmp(arg, "status") == 0) {
ERR("$endif: no matching $if_*");
}
END OBJ(image, 0)
- obj->data.s = strdup(arg ? arg : "");
+ obj->data.s = strndup(arg ? arg : "", text_buffer_size);
#ifdef HAVE_POPEN
END OBJ(exec, 0)
- obj->data.s = strdup(arg ? arg : "");
+ obj->data.s = strndup(arg ? arg : "", text_buffer_size);
END OBJ(execp, 0)
- obj->data.s = strdup(arg ? arg : "");
+ obj->data.s = strndup(arg ? arg : "", text_buffer_size);
END OBJ(execbar, 0)
- obj->data.s = strdup(arg ? arg : "");
+ obj->data.s = strndup(arg ? arg : "", text_buffer_size);
END OBJ(execgraph, 0)
- obj->data.s = strdup(arg ? arg : "");
+ obj->data.s = strndup(arg ? arg : "", text_buffer_size);
END OBJ(execibar, 0)
int n;
ERR("${execibar <interval> command}");
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.execi.cmd = strdup(arg + n);
+ obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
}
END OBJ(execigraph, 0)
int n;
ERR("${execigraph <interval> command}");
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.execi.cmd = strdup(arg + n);
+ obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
}
END OBJ(execi, 0)
int n;
ERR("${execi <interval> command}");
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.execi.cmd = strdup(arg + n);
+ obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
obj->data.execi.buffer = malloc(text_buffer_size);
}
END OBJ(execpi, 0)
ERR("${execi <interval> command}");
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.execi.cmd = strdup(arg + n);
+ obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
obj->data.execi.buffer = malloc(text_buffer_size);
}
END OBJ(texeci, 0)
ERR("${texeci <interval> command}");
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.texeci.cmd = strdup(arg + n);
+ obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
obj->data.texeci.buffer = malloc(text_buffer_size);
}
obj->data.texeci.p_timed_thread = NULL;
pclose(fp);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
} else {
- obj->data.s = strdup("");
+ obj->data.s = strndup("", text_buffer_size);
}
#endif
END OBJ(fs_bar, INFO_FS)
if (!arg) {
ERR("goto needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${goto}");
+ obj->data.s = strndup("${goto}", text_buffer_size);
return NULL;
}
if (!arg) {
ERR("i2c needs arguments");
obj->type = OBJ_text;
- // obj->data.s = strdup("${i2c}");
+ // obj->data.s = strndup("${i2c}", text_buffer_size);
return NULL;
}
if (!arg) {
ERR("top needs arguments");
obj->type = OBJ_text;
- // obj->data.s = strdup("${top}");
+ // obj->data.s = strndup("${top}", text_buffer_size);
return NULL;
}
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (!arg) {
ERR("top_mem needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${top_mem}");
+ obj->data.s = strndup("${top_mem}", text_buffer_size);
return NULL;
}
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (!arg) {
ERR("tail needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${tail}");
+ obj->data.s = strndup("${tail}", text_buffer_size);
return NULL;
}
if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
if (!arg) {
ERR("head needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${head}");
+ obj->data.s = strndup("${head}", text_buffer_size);
return NULL;
}
if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
ERR("if_empty needs an argument");
obj->data.ifblock.s = 0;
} else {
- obj->data.ifblock.s = strdup(arg);
+ obj->data.ifblock.s = strndup(arg, text_buffer_size);
}
blockstart[blockdepth] = object_count;
obj->data.ifblock.pos = object_count + 2;
int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
if (r == 1) {
- obj->data.ifblock.s = strdup(buf1);
+ obj->data.ifblock.s = strndup(buf1, text_buffer_size);
obj->data.ifblock.str = NULL;
} else {
- obj->data.ifblock.s = strdup(buf1);
- obj->data.ifblock.str = strdup(buf2);
+ obj->data.ifblock.s = strndup(buf1, text_buffer_size);
+ obj->data.ifblock.str = strndup(buf2, text_buffer_size);
}
}
blockstart[blockdepth] = object_count;
ERR("if_mounted needs an argument");
obj->data.ifblock.s = 0;
} else {
- obj->data.ifblock.s = strdup(arg);
+ obj->data.ifblock.s = strndup(arg, text_buffer_size);
}
blockstart[blockdepth] = object_count;
obj->data.ifblock.pos = object_count + 2;
char buf[256];
snprintf(buf, 256, "pidof %s >/dev/null", arg);
- obj->data.ifblock.s = strdup(buf);
+ obj->data.ifblock.s = strndup(buf, text_buffer_size);
} else {
ERR("if_running needs an argument");
obj->data.ifblock.s = 0;
}
variable_substitute(box, dst, sizeof(dst));
- obj->data.local_mail.box = strdup(dst);
+ obj->data.local_mail.box = strndup(dst, text_buffer_size);
obj->data.local_mail.interval = n1;
END OBJ(mboxscan, 0)
obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
}
variable_substitute(box, dst, sizeof(dst));
- obj->data.local_mail.box = strdup(dst);
+ obj->data.local_mail.box = strndup(dst, text_buffer_size);
obj->data.local_mail.interval = n1;
END OBJ(nodename, 0)
END OBJ(processes, INFO_PROCS)
&obj->data.sysfs.arg, obj->data.sysfs.devtype);
#endif
END OBJ(time, 0)
- obj->data.s = strdup(arg ? arg : "%F %T");
+ obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
END OBJ(utime, 0)
- obj->data.s = strdup(arg ? arg : "%F %T");
+ obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
END OBJ(tztime, 0)
char buf1[256], buf2[256], *fmt, *tz;
}
}
- obj->data.tztime.fmt = strdup(fmt ? fmt : "%F %T");
- obj->data.tztime.tz = tz ? strdup(tz) : NULL;
+ obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
+ obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
#ifdef HAVE_ICONV
END OBJ(iconv_start, 0)
if (iconv_converting) {
#ifdef SMAPI
END OBJ(smapi, 0)
if (arg)
- obj->data.s = strdup(arg);
+ obj->data.s = strndup(arg, text_buffer_size);
else
ERR("smapi needs an argument");
END OBJ(if_smapi_bat_installed, 0)
ERR("if_smapi_bat_installed needs an argument");
obj->data.ifblock.s = 0;
} else
- obj->data.ifblock.s = strdup(arg);
+ obj->data.ifblock.s = strndup(arg, text_buffer_size);
blockstart[blockdepth] = object_count;
obj->data.ifblock.pos = object_count + 2;
blockdepth++;
END OBJ(smapi_bat_perc, 0)
if (arg)
- obj->data.s = strdup(arg);
+ obj->data.s = strndup(arg, text_buffer_size);
else
ERR("smapi_bat_perc needs an argument");
END OBJ(smapi_bat_bar, 0)
&obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
ERR("hddtemp needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${hddtemp}");
+ obj->data.s = strndup("${hddtemp}", text_buffer_size);
return NULL;
}
#endif
ERR("unknown variable %s", s);
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
- obj->data.s = strdup(buf);
+ obj->data.s = strndup(buf, text_buffer_size);
}
#undef OBJ
obj = new_text_object_internal();
obj->type = OBJ_text;
- obj->data.s = strdup(s);
+ obj->data.s = strndup(s, text_buffer_size);
return obj;
}
char *p, *s, *orig_p;
long line;
- p = strdup(const_p);
+ p = strndup(const_p, max_user_text);
s = orig_p = p;
retval = malloc(sizeof(struct text_object_list));
nt /= 60; // total minutes
if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
nt, nn, cc)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
nn = nt % 60; // minutes past the hour
nt /= 60; // total hours
if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
nn = nt; // now also hours
if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
nn /= 24; // now days
if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
nn /= 7; // now weeks
if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
- return strdup(buf);
+ return strndup(buf, text_buffer_size);
}
// well shoot, this outta' fit...
- return strdup("<inf>");
+ return strndup("<inf>", text_buffer_size);
}
static void generate_text_internal(char *p, int p_max_size,
return 0;
}
- p = strdup(s);
+ p = strndup(s, text_buffer_size);
final = p;
while (*p) {
variable_substitute(MAIL_FILE, buf, 256);
if (buf[0] != '\0') {
- current_mail_spool = strdup(buf);
+ current_mail_spool = strndup(buf, text_buffer_size);
}
}
if (current_mail_spool) {
free(current_mail_spool);
}
- current_mail_spool = strdup(buffer);
+ current_mail_spool = strndup(buffer, text_buffer_size);
}
} else {
CONF_ERR;
if (current_config) {
free(current_config);
}
- current_config = strdup(optarg);
+ current_config = strndup(optarg, max_user_text);
break;
case 'h':
/* Try to use personal config file first */
variable_substitute(CONFIG_FILE, buf, sizeof(buf));
if (buf[0] && (fp = fopen(buf, "r"))) {
- current_config = strdup(buf);
+ current_config = strndup(buf, max_user_text);
fclose(fp);
}
/* Try to use system config file if personal config not readable */
if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
- current_config = strdup(SYSTEM_CONFIG_FILE);
+ current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
fclose(fp);
}
variable_substitute(MAIL_FILE, buf, 256);
if (buf[0] != '\0') {
- current_mail_spool = strdup(buf);
+ current_mail_spool = strndup(buf, text_buffer_size);
}
}
#endif
free(text);
text = 0;
}
- text = strdup(optarg);
+ text = strndup(optarg, max_user_text);
convert_escapes(text);
break;
{
mpd_ReturnElement *ret = malloc(sizeof(mpd_ReturnElement));
- ret->name = strdup(name);
- ret->value = strdup(value);
+ ret->name = strndup(name, text_buffer_size);
+ ret->value = strndup(value, text_buffer_size);
return ret;
}
}
*rt = '\0';
- output = strdup(connection->buffer);
+ output = strndup(connection->buffer, text_buffer_size);
strcpy(connection->buffer, rt + 1);
connection->buflen = strlen(connection->buffer);
status->totalTime = atoi(tok + 1);
}
} else if (strcmp(re->name, "error") == 0) {
- status->error = strdup(re->value);
+ status->error = strndup(re->value, text_buffer_size);
} else if (strcmp(re->name, "xfade") == 0) {
status->crossfade = atoi(re->value);
} else if (strcmp(re->name, "updating_db") == 0) {
mpd_Song *ret = mpd_newSong();
if (song->file) {
- ret->file = strdup(song->file);
+ ret->file = strndup(song->file, text_buffer_size);
}
if (song->artist) {
- ret->artist = strdup(song->artist);
+ ret->artist = strndup(song->artist, text_buffer_size);
}
if (song->album) {
- ret->album = strdup(song->album);
+ ret->album = strndup(song->album, text_buffer_size);
}
if (song->title) {
- ret->title = strdup(song->title);
+ ret->title = strndup(song->title, text_buffer_size);
}
if (song->track) {
- ret->track = strdup(song->track);
+ ret->track = strndup(song->track, text_buffer_size);
}
if (song->name) {
- ret->name = strdup(song->name);
+ ret->name = strndup(song->name, text_buffer_size);
}
if (song->date) {
- ret->date = strdup(song->date);
+ ret->date = strndup(song->date, text_buffer_size);
}
if (song->genre) {
- ret->genre = strdup(song->genre);
+ ret->genre = strndup(song->genre, text_buffer_size);
}
if (song->composer) {
- ret->composer = strdup(song->composer);
+ ret->composer = strndup(song->composer, text_buffer_size);
}
if (song->disc) {
- ret->disc = strdup(song->disc);
+ ret->disc = strndup(song->disc, text_buffer_size);
}
if (song->comment) {
- ret->comment = strdup(song->comment);
+ ret->comment = strndup(song->comment, text_buffer_size);
}
ret->time = song->time;
ret->pos = song->pos;
mpd_Directory *ret = mpd_newDirectory();
if (directory->path) {
- ret->path = strdup(directory->path);
+ ret->path = strndup(directory->path, text_buffer_size);
}
return ret;
mpd_PlaylistFile *ret = mpd_newPlaylistFile();
if (playlist->path) {
- ret->path = strdup(playlist->path);
+ ret->path = strndup(playlist->path, text_buffer_size);
}
return ret;
entity = mpd_newInfoEntity();
entity->type = MPD_INFO_ENTITY_TYPE_SONG;
entity->info.song = mpd_newSong();
- entity->info.song->file = strdup(connection->returnElement->value);
+ entity->info.song->file = strndup(connection->returnElement->value, text_buffer_size);
} else if (strcmp(connection->returnElement->name, "directory") == 0) {
entity = mpd_newInfoEntity();
entity->type = MPD_INFO_ENTITY_TYPE_DIRECTORY;
entity->info.directory = mpd_newDirectory();
entity->info.directory->path =
- strdup(connection->returnElement->value);
+ strndup(connection->returnElement->value, text_buffer_size);
} else if (strcmp(connection->returnElement->name, "playlist") == 0) {
entity = mpd_newInfoEntity();
entity->type = MPD_INFO_ENTITY_TYPE_PLAYLISTFILE;
entity->info.playlistFile = mpd_newPlaylistFile();
entity->info.playlistFile->path =
- strdup(connection->returnElement->value);
+ strndup(connection->returnElement->value, text_buffer_size);
} else if (strcmp(connection->returnElement->name, "cpos") == 0) {
entity = mpd_newInfoEntity();
entity->type = MPD_INFO_ENTITY_TYPE_SONG;
if (entity->type == MPD_INFO_ENTITY_TYPE_SONG && strlen(re->value)) {
if (!entity->info.song->artist
&& strcmp(re->name, "Artist") == 0) {
- entity->info.song->artist = strdup(re->value);
+ entity->info.song->artist = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->album
&& strcmp(re->name, "Album") == 0) {
- entity->info.song->album = strdup(re->value);
+ entity->info.song->album = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->title
&& strcmp(re->name, "Title") == 0) {
- entity->info.song->title = strdup(re->value);
+ entity->info.song->title = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->track
&& strcmp(re->name, "Track") == 0) {
- entity->info.song->track = strdup(re->value);
+ entity->info.song->track = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->name
&& strcmp(re->name, "Name") == 0) {
- entity->info.song->name = strdup(re->value);
+ entity->info.song->name = strndup(re->value, text_buffer_size);
} else if (entity->info.song->time == MPD_SONG_NO_TIME
&& strcmp(re->name, "Time") == 0) {
entity->info.song->time = atoi(re->value);
entity->info.song->id = atoi(re->value);
} else if (!entity->info.song->date
&& strcmp(re->name, "Date") == 0) {
- entity->info.song->date = strdup(re->value);
+ entity->info.song->date = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->genre
&& strcmp(re->name, "Genre") == 0) {
- entity->info.song->genre = strdup(re->value);
+ entity->info.song->genre = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->composer
&& strcmp(re->name, "Composer") == 0) {
- entity->info.song->composer = strdup(re->value);
+ entity->info.song->composer = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->performer
&& strcmp(re->name, "Performer") == 0) {
- entity->info.song->performer = strdup(re->value);
+ entity->info.song->performer = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->disc
&& strcmp(re->name, "Disc") == 0) {
- entity->info.song->disc = strdup(re->value);
+ entity->info.song->disc = strndup(re->value, text_buffer_size);
} else if (!entity->info.song->comment
&& strcmp(re->name, "Comment") == 0) {
- entity->info.song->comment = strdup(re->value);
+ entity->info.song->comment = strndup(re->value, text_buffer_size);
}
} else if (entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
} else if (entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
mpd_ReturnElement *re = connection->returnElement;
if (strcmp(re->name, name) == 0) {
- return strdup(re->value);
+ return strndup(re->value, text_buffer_size);
}
mpd_getNextReturnElement(connection);
}
}
output->id = atoi(re->value);
} else if (strcmp(re->name, "outputname") == 0) {
- output->name = strdup(re->value);
+ output->name = strndup(re->value, text_buffer_size);
} else if (strcmp(re->name, "outputenabled") == 0) {
output->enabled = atoi(re->value);
}
}
if (exact) {
- connection->request = strdup("find");
+ connection->request = strndup("find", text_buffer_size);
} else {
- connection->request = strdup("search");
+ connection->request = strndup("search", text_buffer_size);
}
}
return;
}
- connection->request = strdup("count");
+ connection->request = strndup("count", text_buffer_size);
}
void mpd_startPlaylistSearch(mpd_Connection *connection, int exact)
}
if (exact) {
- connection->request = strdup("playlistfind");
+ connection->request = strndup("playlistfind", text_buffer_size);
} else {
- connection->request = strdup("playlistsearch");
+ connection->request = strndup("playlistsearch", text_buffer_size);
}
}
return;
}
- string = strdup(connection->request);
+ string = strndup(connection->request, text_buffer_size);
strtype = mpdTagItemKeys[type];
arg = mpd_sanitizeArg(name);