Use strcmp() instead of strncmp()
strncmp() isn't intended to be a secure strcmp() replacement, it is designed to be used if you want to compare the first n characters of two strings. Since we always compare character pointers with string literals, switch to using strcmp() everywhere. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
7072c9c88a
commit
2c9499bf27
@ -117,9 +117,9 @@ typedef int (*config_fn_walk_junk_cb_t) (const char *, void *);
|
|||||||
static int
|
static int
|
||||||
config_parse_bool (unsigned *dest, const char *val)
|
config_parse_bool (unsigned *dest, const char *val)
|
||||||
{
|
{
|
||||||
if (strncmp (val, "yes", 4) == 0)
|
if (strcmp (val, "yes") == 0)
|
||||||
*dest = 1;
|
*dest = 1;
|
||||||
else if (strncmp (val, "no", 3) == 0)
|
else if (strcmp (val, "no") == 0)
|
||||||
*dest = 0;
|
*dest = 0;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
44
src/ical.c
44
src/ical.c
@ -472,7 +472,7 @@ ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
|
|||||||
return HEADER_MALFORMED;
|
return HEADER_MALFORMED;
|
||||||
|
|
||||||
str_toupper (buf);
|
str_toupper (buf);
|
||||||
if (strncmp (buf, icalheader.str, icalheader.len) != 0)
|
if (strcmp (buf, icalheader.str) != 0)
|
||||||
return HEADER_MALFORMED;
|
return HEADER_MALFORMED;
|
||||||
|
|
||||||
while (!sscanf (buf, "VERSION:%f", &version))
|
while (!sscanf (buf, "VERSION:%f", &version))
|
||||||
@ -730,13 +730,13 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strncmp (freqstr, daily.str, daily.len) == 0)
|
if (strcmp (freqstr, daily.str) == 0)
|
||||||
rpt->type = RECUR_DAILY;
|
rpt->type = RECUR_DAILY;
|
||||||
else if (strncmp (freqstr, weekly.str, weekly.len) == 0)
|
else if (strcmp (freqstr, weekly.str) == 0)
|
||||||
rpt->type = RECUR_WEEKLY;
|
rpt->type = RECUR_WEEKLY;
|
||||||
else if (strncmp (freqstr, monthly.str, monthly.len) == 0)
|
else if (strcmp (freqstr, monthly.str) == 0)
|
||||||
rpt->type = RECUR_MONTHLY;
|
rpt->type = RECUR_MONTHLY;
|
||||||
else if (strncmp (freqstr, yearly.str, yearly.len) == 0)
|
else if (strcmp (freqstr, yearly.str) == 0)
|
||||||
rpt->type = RECUR_YEARLY;
|
rpt->type = RECUR_YEARLY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -955,11 +955,11 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
{
|
{
|
||||||
/* Need to skip VALARM properties because some keywords could
|
/* Need to skip VALARM properties because some keywords could
|
||||||
interfere, such as DURATION, SUMMARY,.. */
|
interfere, such as DURATION, SUMMARY,.. */
|
||||||
if (strncmp (buf_upper, endalarm.str, endalarm.len) == 0)
|
if (strcmp (buf_upper, endalarm.str) == 0)
|
||||||
skip_alarm = 0;
|
skip_alarm = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp (buf_upper, endevent.str, endevent.len) == 0)
|
if (strcmp (buf_upper, endevent.str) == 0)
|
||||||
{
|
{
|
||||||
if (vevent.mesg)
|
if (vevent.mesg)
|
||||||
{
|
{
|
||||||
@ -1039,7 +1039,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strncmp (buf_upper, dtstart.str, dtstart.len) == 0)
|
if (strcmp (buf_upper, dtstart.str) == 0)
|
||||||
{
|
{
|
||||||
if ((p = strchr (buf, ':')) != NULL)
|
if ((p = strchr (buf, ':')) != NULL)
|
||||||
vevent.start = ical_datetime2long (++p, &vevent_type);
|
vevent.start = ical_datetime2long (++p, &vevent_type);
|
||||||
@ -1050,7 +1050,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, dtend.str, dtend.len) == 0)
|
else if (strcmp (buf_upper, dtend.str) == 0)
|
||||||
{
|
{
|
||||||
if ((p = strchr (buf, ':')) != NULL)
|
if ((p = strchr (buf, ':')) != NULL)
|
||||||
vevent.end = ical_datetime2long (++p, &vevent_type);
|
vevent.end = ical_datetime2long (++p, &vevent_type);
|
||||||
@ -1061,7 +1061,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, duration.str, duration.len) == 0)
|
else if (strcmp (buf_upper, duration.str) == 0)
|
||||||
{
|
{
|
||||||
if ((vevent.dur = ical_dur2long (buf)) <= 0)
|
if ((vevent.dur = ical_dur2long (buf)) <= 0)
|
||||||
{
|
{
|
||||||
@ -1070,24 +1070,24 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, rrule.str, rrule.len) == 0)
|
else if (strcmp (buf_upper, rrule.str) == 0)
|
||||||
{
|
{
|
||||||
vevent.rpt = ical_read_rrule (log, buf, noskipped, ITEMLINE);
|
vevent.rpt = ical_read_rrule (log, buf, noskipped, ITEMLINE);
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, exdate.str, exdate.len) == 0)
|
else if (strcmp (buf_upper, exdate.str) == 0)
|
||||||
{
|
{
|
||||||
ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE);
|
ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE);
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, summary.str, summary.len) == 0)
|
else if (strcmp (buf_upper, summary.str) == 0)
|
||||||
{
|
{
|
||||||
vevent.mesg = ical_read_summary (buf);
|
vevent.mesg = ical_read_summary (buf);
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, alarm.str, alarm.len) == 0)
|
else if (strcmp (buf_upper, alarm.str) == 0)
|
||||||
{
|
{
|
||||||
skip_alarm = 1;
|
skip_alarm = 1;
|
||||||
vevent.has_alarm = 1;
|
vevent.has_alarm = 1;
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, desc.str, desc.len) == 0)
|
else if (strcmp (buf_upper, desc.str) == 0)
|
||||||
{
|
{
|
||||||
vevent.note = ical_read_note (buf, noskipped, ICAL_VEVENT,
|
vevent.note = ical_read_note (buf, noskipped, ICAL_VEVENT,
|
||||||
ITEMLINE, log);
|
ITEMLINE, log);
|
||||||
@ -1139,11 +1139,11 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
|||||||
{
|
{
|
||||||
/* Need to skip VALARM properties because some keywords could
|
/* Need to skip VALARM properties because some keywords could
|
||||||
interfere, such as DURATION, SUMMARY,.. */
|
interfere, such as DURATION, SUMMARY,.. */
|
||||||
if (strncmp (buf_upper, endalarm.str, endalarm.len) == 0)
|
if (strcmp (buf_upper, endalarm.str) == 0)
|
||||||
skip_alarm = 0;
|
skip_alarm = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp (buf_upper, endtodo.str, endtodo.len) == 0)
|
if (strcmp (buf_upper, endtodo.str) == 0)
|
||||||
{
|
{
|
||||||
if (!vtodo.has_priority)
|
if (!vtodo.has_priority)
|
||||||
vtodo.priority = LOWEST;
|
vtodo.priority = LOWEST;
|
||||||
@ -1179,15 +1179,15 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
|||||||
vtodo.priority = LOWEST;
|
vtodo.priority = LOWEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, summary.str, summary.len) == 0)
|
else if (strcmp (buf_upper, summary.str) == 0)
|
||||||
{
|
{
|
||||||
vtodo.mesg = ical_read_summary (buf);
|
vtodo.mesg = ical_read_summary (buf);
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, alarm.str, alarm.len) == 0)
|
else if (strcmp (buf_upper, alarm.str) == 0)
|
||||||
{
|
{
|
||||||
skip_alarm = 1;
|
skip_alarm = 1;
|
||||||
}
|
}
|
||||||
else if (strncmp (buf_upper, desc.str, desc.len) == 0)
|
else if (strcmp (buf_upper, desc.str) == 0)
|
||||||
{
|
{
|
||||||
vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO,
|
vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO,
|
||||||
ITEMLINE, log);
|
ITEMLINE, log);
|
||||||
@ -1229,12 +1229,12 @@ ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
|
|||||||
{
|
{
|
||||||
(*lines)++;
|
(*lines)++;
|
||||||
str_toupper (buf);
|
str_toupper (buf);
|
||||||
if (strncmp (buf, vevent.str, vevent.len) == 0)
|
if (strcmp (buf, vevent.str) == 0)
|
||||||
{
|
{
|
||||||
ical_read_event (stream, log, events, apoints, skipped, buf, lstore,
|
ical_read_event (stream, log, events, apoints, skipped, buf, lstore,
|
||||||
lines);
|
lines);
|
||||||
}
|
}
|
||||||
else if (strncmp (buf, vtodo.str, vtodo.len) == 0)
|
else if (strcmp (buf, vtodo.str) == 0)
|
||||||
{
|
{
|
||||||
ical_read_todo (stream, log, todos, skipped, buf, lstore, lines);
|
ical_read_todo (stream, log, todos, skipped, buf, lstore, lines);
|
||||||
}
|
}
|
||||||
|
20
src/keys.c
20
src/keys.c
@ -322,25 +322,25 @@ keys_str2int (char *key)
|
|||||||
{
|
{
|
||||||
if (key[0] == '^')
|
if (key[0] == '^')
|
||||||
return CTRL ((int)key[1]);
|
return CTRL ((int)key[1]);
|
||||||
else if (!strncmp (key, CONTROL_KEY.str, CONTROL_KEY.len))
|
else if (!strcmp (key, CONTROL_KEY.str))
|
||||||
return CTRL ((int)key[CONTROL_KEY.len]);
|
return CTRL ((int)key[CONTROL_KEY.len]);
|
||||||
else if (!strncmp (key, TAB_KEY.str, TAB_KEY.len))
|
else if (!strcmp (key, TAB_KEY.str))
|
||||||
return TAB;
|
return TAB;
|
||||||
else if (!strncmp (key, ESCAPE_KEY.str, ESCAPE_KEY.len))
|
else if (!strcmp (key, ESCAPE_KEY.str))
|
||||||
return ESCAPE;
|
return ESCAPE;
|
||||||
else if (!strncmp (key, SPACE_KEY.str, SPACE_KEY.len))
|
else if (!strcmp (key, SPACE_KEY.str))
|
||||||
return SPACE;
|
return SPACE;
|
||||||
else if (!strncmp (key, CURSES_KEY_UP.str, CURSES_KEY_UP.len))
|
else if (!strcmp (key, CURSES_KEY_UP.str))
|
||||||
return KEY_UP;
|
return KEY_UP;
|
||||||
else if (!strncmp (key, CURSES_KEY_DOWN.str, CURSES_KEY_DOWN.len))
|
else if (!strcmp (key, CURSES_KEY_DOWN.str))
|
||||||
return KEY_DOWN;
|
return KEY_DOWN;
|
||||||
else if (!strncmp (key, CURSES_KEY_LEFT.str, CURSES_KEY_LEFT.len))
|
else if (!strcmp (key, CURSES_KEY_LEFT.str))
|
||||||
return KEY_LEFT;
|
return KEY_LEFT;
|
||||||
else if (!strncmp (key, CURSES_KEY_RIGHT.str, CURSES_KEY_RIGHT.len))
|
else if (!strcmp (key, CURSES_KEY_RIGHT.str))
|
||||||
return KEY_RIGHT;
|
return KEY_RIGHT;
|
||||||
else if (!strncmp (key, CURSES_KEY_HOME.str, CURSES_KEY_HOME.len))
|
else if (!strcmp (key, CURSES_KEY_HOME.str))
|
||||||
return KEY_HOME;
|
return KEY_HOME;
|
||||||
else if (!strncmp (key, CURSES_KEY_END.str, CURSES_KEY_END.len))
|
else if (!strcmp (key, CURSES_KEY_END.str))
|
||||||
return KEY_END;
|
return KEY_END;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -943,7 +943,7 @@ recur_repeat_item (void)
|
|||||||
status_mesg (_(outstr), "");
|
status_mesg (_(outstr), "");
|
||||||
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
|
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
|
||||||
{
|
{
|
||||||
if (strlen (user_input) == 1 && strncmp (user_input, "0", 1) == 0)
|
if (strlen (user_input) == 1 && strcmp (user_input, "0") == 0)
|
||||||
{
|
{
|
||||||
until = 0;
|
until = 0;
|
||||||
date_entered = 1;
|
date_entered = 1;
|
||||||
|
@ -418,7 +418,7 @@ item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
|
|||||||
|
|
||||||
pad = newpad (padl, padw);
|
pad = newpad (padl, padw);
|
||||||
popup_win = popup (winl, winw, 1, 2, pop_title, NULL, 1);
|
popup_win = popup (winl, winw, 1, 2, pop_title, NULL, 1);
|
||||||
if (strncmp (pop_title, _("Appointment"), 11) == 0)
|
if (strcmp (pop_title, _("Appointment")) == 0)
|
||||||
{
|
{
|
||||||
mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s",
|
mvwprintw (popup_win, margin_top, margin_left, "- %s -> %s",
|
||||||
saved_a_start, saved_a_end);
|
saved_a_start, saved_a_end);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user