Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
CID 90850 mod_announce: Check motd-message existence
Browse files Browse the repository at this point in the history
  • Loading branch information
smokku committed May 3, 2016
1 parent de8ecb7 commit c4f0ffc
Showing 1 changed file with 46 additions and 45 deletions.
91 changes: 46 additions & 45 deletions sm/mod_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,51 +59,52 @@ static void _announce_load(module_t mod, moddata_t data, const char *domain) {

/* load the current message */
if((ret = storage_get(mod->mm->sm->st, "motd-message", domain, NULL, &os)) == st_SUCCESS) {
os_iter_first(os);
o = os_iter_object(os);
if(os_object_get_nad(os, o, "xml", &nad)) {
/* Copy the nad, as the original is freed when the os is freed below */
data->nad = nad_copy(nad);
if((ns = nad_find_scoped_namespace(data->nad, uri_DELAY, NULL)) >= 0 &&
(elem = nad_find_elem(data->nad, 1, ns, "x", 1)) >= 0 &&
(attr = nad_find_attr(data->nad, elem, -1, "stamp", NULL)) >= 0) {
snprintf(timestamp, 18, "%.*s", NAD_AVAL_L(data->nad, attr), NAD_AVAL(data->nad, attr));

/* year */
telem[0] = timestamp[0];
telem[1] = timestamp[1];
telem[2] = timestamp[2];
telem[3] = timestamp[3];
telem[4] = '\0';
tm.tm_year = atoi(telem) - 1900;

/* month */
telem[0] = timestamp[4];
telem[1] = timestamp[5];
telem[2] = '\0';
tm.tm_mon = atoi(telem) - 1;

/* day */
telem[0] = timestamp[6];
telem[1] = timestamp[7];
tm.tm_mday = atoi(telem);

/* hour */
telem[0] = timestamp[9];
telem[1] = timestamp[10];
tm.tm_hour = atoi(telem);

/* minute */
telem[0] = timestamp[12];
telem[1] = timestamp[13];
tm.tm_min = atoi(telem);

/* second */
telem[0] = timestamp[15];
telem[1] = timestamp[16];
tm.tm_sec = atoi(telem);

data->t = timegm(&tm);
if(os_iter_first(os)) {
o = os_iter_object(os);
if(os_object_get_nad(os, o, "xml", &nad)) {
/* Copy the nad, as the original is freed when the os is freed below */
data->nad = nad_copy(nad);
if((ns = nad_find_scoped_namespace(data->nad, uri_DELAY, NULL)) >= 0 &&
(elem = nad_find_elem(data->nad, 1, ns, "x", 1)) >= 0 &&
(attr = nad_find_attr(data->nad, elem, -1, "stamp", NULL)) >= 0) {
snprintf(timestamp, 18, "%.*s", NAD_AVAL_L(data->nad, attr), NAD_AVAL(data->nad, attr));

/* year */
telem[0] = timestamp[0];
telem[1] = timestamp[1];
telem[2] = timestamp[2];
telem[3] = timestamp[3];
telem[4] = '\0';
tm.tm_year = atoi(telem) - 1900;

/* month */
telem[0] = timestamp[4];
telem[1] = timestamp[5];
telem[2] = '\0';
tm.tm_mon = atoi(telem) - 1;

/* day */
telem[0] = timestamp[6];
telem[1] = timestamp[7];
tm.tm_mday = atoi(telem);

/* hour */
telem[0] = timestamp[9];
telem[1] = timestamp[10];
tm.tm_hour = atoi(telem);

/* minute */
telem[0] = timestamp[12];
telem[1] = timestamp[13];
tm.tm_min = atoi(telem);

/* second */
telem[0] = timestamp[15];
telem[1] = timestamp[16];
tm.tm_sec = atoi(telem);

data->t = timegm(&tm);
}
}
}

Expand Down

0 comments on commit c4f0ffc

Please sign in to comment.