1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

* Replacing strdup() with strndup() throughout

(this is probably going to break a few things)

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1100 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2008-04-02 18:44:49 +00:00
parent d46bcb0945
commit a6a4a4c548
13 changed files with 137 additions and 136 deletions

View File

@ -2,6 +2,7 @@
2008-04-02
* Added patch to use mail_spool correctly (thanks Kapil)
* Replacing strdup() with strndup() throughout
2008-04-01
* Fixed segfault when configuration doesn't contain TEXT block (thanks

View File

@ -143,7 +143,7 @@ struct net_stat *get_net_stat(const char *dev)
if (i == 16) {
for (i = 0; i < 16; i++) {
if (netstats[i].dev == 0) {
netstats[i].dev = strdup(dev);
netstats[i].dev = strndup(dev, text_buffer_size);
return &netstats[i];
}
}
@ -195,7 +195,7 @@ void update_dns_data(void)
line[strlen(line) - 1] = '\0'; // remove trailing newline
data->nscount++;
data->ns_list = realloc(data->ns_list, data->nscount * sizeof(char *));
data->ns_list[data->nscount - 1] = strdup(line + 11);
data->ns_list[data->nscount - 1] = strndup(line + 11, text_buffer_size);
}
}
OUT:

View File

@ -216,7 +216,7 @@ int addfont(const char *data_in)
}
// 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
@ -237,7 +237,7 @@ void set_first_font(const char *data_in)
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
@ -675,7 +675,7 @@ static const char *scan_bar(const char *args, int *w, int *h)
static char *scan_font(const char *args)
{
if (args && *args) {
return strdup(args);
return strndup(args, text_buffer_size);
}
return NULL;
@ -814,12 +814,12 @@ static char *scan_graph(const char *args, int *w, int *h,
}
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;
@ -833,11 +833,11 @@ static char *scan_graph(const char *args, int *w, int *h,
}
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;
@ -855,13 +855,13 @@ static char *scan_graph(const char *args, int *w, int *h,
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);
}
}
@ -2428,7 +2428,7 @@ static struct text_object *construct_text_object(const char *s,
} 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];
@ -2437,7 +2437,7 @@ static struct text_object *construct_text_object(const char *s,
} 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];
@ -2446,7 +2446,7 @@ static struct text_object *construct_text_object(const char *s,
} 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;
@ -2456,13 +2456,13 @@ static struct text_object *construct_text_object(const char *s,
} 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)
@ -2497,7 +2497,7 @@ static struct text_object *construct_text_object(const char *s,
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++;
@ -2513,7 +2513,7 @@ static struct text_object *construct_text_object(const char *s,
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) {
@ -2718,16 +2718,16 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -2737,9 +2737,9 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -2750,9 +2750,9 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -2763,9 +2763,9 @@ static struct text_object *construct_text_object(const char *s,
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)
@ -2777,9 +2777,9 @@ static struct text_object *construct_text_object(const char *s,
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)
@ -2791,9 +2791,9 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -2813,9 +2813,9 @@ static struct text_object *construct_text_object(const char *s,
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)
@ -2888,7 +2888,7 @@ static struct text_object *construct_text_object(const char *s,
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;
}
@ -2916,7 +2916,7 @@ static struct text_object *construct_text_object(const char *s,
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;
}
@ -2987,7 +2987,7 @@ static struct text_object *construct_text_object(const char *s,
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) {
@ -3027,7 +3027,7 @@ static struct text_object *construct_text_object(const char *s,
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) {
@ -3082,7 +3082,7 @@ static struct text_object *construct_text_object(const char *s,
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) {
@ -3184,7 +3184,7 @@ static struct text_object *construct_text_object(const char *s,
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) {
@ -3265,7 +3265,7 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -3283,11 +3283,11 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -3301,7 +3301,7 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -3314,7 +3314,7 @@ static struct text_object *construct_text_object(const char *s,
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;
@ -3344,7 +3344,7 @@ static struct text_object *construct_text_object(const char *s,
}
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);
@ -3399,7 +3399,7 @@ static struct text_object *construct_text_object(const char *s,
}
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)
@ -3444,9 +3444,9 @@ static struct text_object *construct_text_object(const char *s,
&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;
@ -3462,8 +3462,8 @@ static struct text_object *construct_text_object(const char *s,
}
}
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) {
@ -3587,7 +3587,7 @@ static struct text_object *construct_text_object(const char *s,
#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)
@ -3598,13 +3598,13 @@ static struct text_object *construct_text_object(const char *s,
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)
@ -3735,7 +3735,7 @@ static struct text_object *construct_text_object(const char *s,
&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
@ -3835,7 +3835,7 @@ static struct text_object *construct_text_object(const char *s,
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
@ -3853,7 +3853,7 @@ static struct text_object *create_plain_text(const char *s)
obj = new_text_object_internal();
obj->type = OBJ_text;
obj->data.s = strdup(s);
obj->data.s = strndup(s, text_buffer_size);
return obj;
}
@ -3864,7 +3864,7 @@ static struct text_object_list *extract_variable_text_internal(const char *const
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));
@ -4145,30 +4145,30 @@ char *format_time(unsigned long timeval, const int width)
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,
@ -6294,7 +6294,7 @@ static inline int get_string_width_special(char *s)
return 0;
}
p = strdup(s);
p = strndup(s, text_buffer_size);
final = p;
while (*p) {
@ -7779,7 +7779,7 @@ static void set_default_configurations(void)
variable_substitute(MAIL_FILE, buf, 256);
if (buf[0] != '\0') {
current_mail_spool = strdup(buf);
current_mail_spool = strndup(buf, text_buffer_size);
}
}
@ -8193,7 +8193,7 @@ static void load_config_file(const char *f)
if (current_mail_spool) {
free(current_mail_spool);
}
current_mail_spool = strdup(buffer);
current_mail_spool = strndup(buffer, text_buffer_size);
}
} else {
CONF_ERR;
@ -8541,7 +8541,7 @@ int main(int argc, char **argv)
if (current_config) {
free(current_config);
}
current_config = strdup(optarg);
current_config = strndup(optarg, max_user_text);
break;
case 'h':
@ -8609,13 +8609,13 @@ int main(int argc, char **argv)
/* 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);
}
@ -8639,7 +8639,7 @@ int main(int argc, char **argv)
variable_substitute(MAIL_FILE, buf, 256);
if (buf[0] != '\0') {
current_mail_spool = strdup(buf);
current_mail_spool = strndup(buf, text_buffer_size);
}
}
#endif
@ -8696,7 +8696,7 @@ int main(int argc, char **argv)
free(text);
text = 0;
}
text = strdup(optarg);
text = strndup(optarg, max_user_text);
convert_escapes(text);
break;

View File

@ -760,7 +760,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
for (i = 0; i < n_processes; i++) {
if (!((p[i].ki_flag & P_SYSTEM)) && p[i].ki_comm != NULL) {
processes[j].pid = p[i].ki_pid;
processes[j].name = strdup(p[i].ki_comm);
processes[j].name = strndup(p[i].ki_comm, text_buffer_size);
processes[j].amount = 100.0 * p[i].ki_pctcpu / FSCALE;
processes[j].totalmem = (float) (p[i].ki_rssize /
(float) total_pages) * 100.0;
@ -778,7 +778,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
tmp->pid = processes[i].pid;
tmp->amount = processes[i].amount;
tmp->totalmem = processes[i].totalmem;
tmp->name = strdup(processes[i].name);
tmp->name = strndup(processes[i].name, text_buffer_size);
tmp->rss = processes[i].rss;
tmp->vsize = processes[i].vsize;
@ -798,7 +798,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
tmp->pid = processes[i].pid;
tmp->amount = processes[i].amount;
tmp->totalmem = processes[i].totalmem;
tmp->name = strdup(processes[i].name);
tmp->name = strndup(processes[i].name, text_buffer_size);
tmp->rss = processes[i].rss;
tmp->vsize = processes[i].vsize;

View File

@ -57,12 +57,12 @@ int scan_hddtemp(const char *arg, char **dev, char **addr, int *port)
strncpy(buf1 + 5, buf1, 32 - 5);
strncpy(buf1, "/dev/", 5);
}
*dev = strdup(buf1);
*dev = strndup(buf1, text_buffer_size);
if (ret >= 2) {
*addr = strdup(buf2);
*addr = strndup(buf2, text_buffer_size);
} else {
*addr = strdup("127.0.0.1");
*addr = strndup("127.0.0.1", text_buffer_size);
}
if (ret == 3) {

View File

@ -293,8 +293,8 @@ static mpd_ReturnElement *mpd_newReturnElement(const char *name,
{
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;
}
@ -415,7 +415,7 @@ mpd_Connection *mpd_newConnection(const char *host, int port, float timeout)
}
*rt = '\0';
output = strdup(connection->buffer);
output = strndup(connection->buffer, text_buffer_size);
strcpy(connection->buffer, rt + 1);
connection->buflen = strlen(connection->buffer);
@ -768,7 +768,7 @@ mpd_Status *mpd_getStatus(mpd_Connection *connection)
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) {
@ -1018,37 +1018,37 @@ mpd_Song *mpd_songDup(mpd_Song *song)
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;
@ -1090,7 +1090,7 @@ mpd_Directory *mpd_directoryDup(mpd_Directory *directory)
mpd_Directory *ret = mpd_newDirectory();
if (directory->path) {
ret->path = strdup(directory->path);
ret->path = strndup(directory->path, text_buffer_size);
}
return ret;
@ -1128,7 +1128,7 @@ mpd_PlaylistFile *mpd_playlistFileDup(mpd_PlaylistFile *playlist)
mpd_PlaylistFile *ret = mpd_newPlaylistFile();
if (playlist->path) {
ret->path = strdup(playlist->path);
ret->path = strndup(playlist->path, text_buffer_size);
}
return ret;
@ -1190,19 +1190,19 @@ mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection *connection)
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;
@ -1234,19 +1234,19 @@ mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection *connection)
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);
@ -1258,22 +1258,22 @@ mpd_InfoEntity *mpd_getNextInfoEntity(mpd_Connection *connection)
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) {
@ -1298,7 +1298,7 @@ static char *mpd_getNextReturnElementNamed(mpd_Connection *connection,
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);
}
@ -1835,7 +1835,7 @@ mpd_OutputEntity *mpd_getNextOutput(mpd_Connection *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);
}
@ -1923,9 +1923,9 @@ void mpd_startSearch(mpd_Connection *connection, int exact)
}
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);
}
}
@ -1937,7 +1937,7 @@ void mpd_startStatsSearch(mpd_Connection *connection)
return;
}
connection->request = strdup("count");
connection->request = strndup("count", text_buffer_size);
}
void mpd_startPlaylistSearch(mpd_Connection *connection, int exact)
@ -1949,9 +1949,9 @@ 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);
}
}
@ -2007,7 +2007,7 @@ void mpd_addConstraintSearch(mpd_Connection *connection, int type,
return;
}
string = strdup(connection->request);
string = strndup(connection->request, text_buffer_size);
strtype = mpdTagItemKeys[type];
arg = mpd_sanitizeArg(name);

View File

@ -192,22 +192,22 @@ char *get_ioscheduler(char *disk)
char buf[128];
if (!disk)
return strdup("n/a");
return strndup("n/a", text_buffer_size);
snprintf(buf, 127, "/sys/block/%s/queue/scheduler", disk);
if ((fp = fopen(buf, "r")) == NULL) {
return strdup("n/a");
return strndup("n/a", text_buffer_size);
}
while (!feof(fp)) {
fscanf(fp, "%127s", buf);
if (buf[0] == '[') {
buf[strlen(buf) - 1] = '\0';
fclose(fp);
return strdup(buf + 1);
return strndup(buf + 1, text_buffer_size);
}
}
fclose(fp);
return strdup("n/a");
return strndup("n/a", text_buffer_size);
}
int interface_up(const char *dev)
@ -236,9 +236,9 @@ int interface_up(const char *dev)
#define SAVE_SET_STRING(x, y) \
if (x && strcmp((char *)x, (char *)y)) { \
free(x); \
x = strdup("multiple"); \
x = strndup("multiple", text_buffer_size); \
} else if (!x) { \
x = strdup(y); \
x = strndup(y, text_buffer_size); \
}
void update_gateway_info(void)
@ -284,7 +284,7 @@ void update_gateway_info(void)
CLOSE_FAIL:
fclose(fp);
FAIL:
info.gw_info.iface = info.gw_info.ip = strdup("failed");
info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size);
return;
}

View File

@ -124,7 +124,7 @@ void mbox_scan(char *args, char *output, size_t max_len)
start[(long) (strrchr(mbox_mail_spool, '"') - start)] = '\0';
strncpy(mbox_mail_spool, start, DEFAULT_TEXT_BUFFER_SIZE);
} else {
char *copy_args = strdup(args);
char *copy_args = strndup(args, text_buffer_size);
char *tmp = strtok(copy_args, " ");
char *start = tmp;

View File

@ -716,7 +716,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
for (i = 0; i < n_processes; i++) {
if (!((p[i].p_flag & P_SYSTEM)) && p[i].p_comm != NULL) {
processes[j].pid = p[i].p_pid;
processes[j].name = strdup(p[i].p_comm);
processes[j].name = strndup(p[i].p_comm, text_buffer_size);
processes[j].amount = 100.0 * p[i].p_pctcpu / FSCALE;
processes[j].totalmem = (float) (p[i].p_vm_rssize * pagesize /
(float) total_pages) * 100.0;
@ -732,7 +732,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
tmp->pid = processes[i].pid;
tmp->amount = processes[i].amount;
tmp->totalmem = processes[i].totalmem;
tmp->name = strdup(processes[i].name);
tmp->name = strndup(processes[i].name, text_buffer_size);
ttmp = mem[i];
mem[i] = tmp;
@ -750,7 +750,7 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
tmp->pid = processes[i].pid;
tmp->amount = processes[i].amount;
tmp->totalmem = processes[i].totalmem;
tmp->name = strdup(processes[i].name);
tmp->name = strndup(processes[i].name, text_buffer_size);
ttmp = cpu[i];
cpu[i] = tmp;

View File

@ -171,7 +171,7 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root)
}
}
res->version = strdup("2.0");
res->version = strndup("2.0", text_buffer_size);
res->items = malloc(items * sizeof(PRSS_Item));
res->item_count = 0;
@ -200,7 +200,7 @@ static inline int parse_rss_1_0(PRSS *res, xmlNodePtr root)
}
}
res->version = strdup("1.0");
res->version = strndup("1.0", text_buffer_size);
res->items = malloc(items * sizeof(PRSS_Item));
res->item_count = 0;

View File

@ -143,7 +143,7 @@ PRSS *get_rss_info(char *uri, int delay)
return NULL;
}
curfeed = &feeds[num_feeds];
curfeed->uri = strdup(uri);
curfeed->uri = strndup(uri, text_buffer_size);
num_feeds++;
}

View File

@ -50,7 +50,7 @@ char *smapi_read_str(const char *path)
fscanf(fp, "%255s\n", str);
fclose(fp);
}
return strdup(str);
return strndup(str, text_buffer_size);
}
int smapi_read_int(const char *path)

View File

@ -183,7 +183,7 @@ static int process_parse_stat(struct process *process)
if (process->name) {
free(process->name);
}
process->name = strdup(deparenthesised_name);
process->name = strndup(deparenthesised_name, text_buffer_size);
process->rss *= getpagesize();
if (!cur->memmax) {