Message ID | 1367887460-25000-1-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On 05/07/2013 08:44 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > Coverity CID #997313, Unchecked return value from library > > Check return from lstat rather than blindly accepting that > it always works. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/hotkey/hotkey/hotkey.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c > index ff3c669..381f029 100644 > --- a/src/hotkey/hotkey/hotkey.c > +++ b/src/hotkey/hotkey/hotkey.c > @@ -154,19 +154,20 @@ static char *hotkey_find_keyboard(char *path) > if (strlen(entry->d_name) > 3) { > snprintf(filename, sizeof(filename), "%s/%s", > path, entry->d_name); > - lstat(filename, &statbuf); > - if (S_ISDIR(statbuf.st_mode)) { > - if (!S_ISLNK(statbuf.st_mode)) > - if ((dev = hotkey_find_keyboard(filename)) != NULL) > - break; > - } else { > - if ((data = fwts_get(filename)) != NULL) { > - if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { > - dev = hotkey_device(path); > + if (lstat(filename, &statbuf) == 0) { > + if (S_ISDIR(statbuf.st_mode)) { > + if (!S_ISLNK(statbuf.st_mode)) > + if ((dev = hotkey_find_keyboard(filename)) != NULL) > + break; > + } else { > + if ((data = fwts_get(filename)) != NULL) { > + if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { > + dev = hotkey_device(path); > + free(data); > + break; > + } > free(data); > - break; > } > - free(data); > } > } > } > Acked-by: Alex Hung <alex.hung@canonical.com>
On Tue, May 7, 2013 at 8:44 AM, Colin King <colin.king@canonical.com> wrote: > From: Colin Ian King <colin.king@canonical.com> > > Coverity CID #997313, Unchecked return value from library > > Check return from lstat rather than blindly accepting that > it always works. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/hotkey/hotkey/hotkey.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c > index ff3c669..381f029 100644 > --- a/src/hotkey/hotkey/hotkey.c > +++ b/src/hotkey/hotkey/hotkey.c > @@ -154,19 +154,20 @@ static char *hotkey_find_keyboard(char *path) > if (strlen(entry->d_name) > 3) { > snprintf(filename, sizeof(filename), "%s/%s", > path, entry->d_name); > - lstat(filename, &statbuf); > - if (S_ISDIR(statbuf.st_mode)) { > - if (!S_ISLNK(statbuf.st_mode)) > - if ((dev = hotkey_find_keyboard(filename)) != NULL) > - break; > - } else { > - if ((data = fwts_get(filename)) != NULL) { > - if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { > - dev = hotkey_device(path); > + if (lstat(filename, &statbuf) == 0) { > + if (S_ISDIR(statbuf.st_mode)) { > + if (!S_ISLNK(statbuf.st_mode)) > + if ((dev = hotkey_find_keyboard(filename)) != NULL) > + break; > + } else { > + if ((data = fwts_get(filename)) != NULL) { > + if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { > + dev = hotkey_device(path); > + free(data); > + break; > + } > free(data); > - break; > } > - free(data); > } > } > } > -- > 1.8.1.2 > Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c index ff3c669..381f029 100644 --- a/src/hotkey/hotkey/hotkey.c +++ b/src/hotkey/hotkey/hotkey.c @@ -154,19 +154,20 @@ static char *hotkey_find_keyboard(char *path) if (strlen(entry->d_name) > 3) { snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name); - lstat(filename, &statbuf); - if (S_ISDIR(statbuf.st_mode)) { - if (!S_ISLNK(statbuf.st_mode)) - if ((dev = hotkey_find_keyboard(filename)) != NULL) - break; - } else { - if ((data = fwts_get(filename)) != NULL) { - if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { - dev = hotkey_device(path); + if (lstat(filename, &statbuf) == 0) { + if (S_ISDIR(statbuf.st_mode)) { + if (!S_ISLNK(statbuf.st_mode)) + if ((dev = hotkey_find_keyboard(filename)) != NULL) + break; + } else { + if ((data = fwts_get(filename)) != NULL) { + if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) { + dev = hotkey_device(path); + free(data); + break; + } free(data); - break; } - free(data); } } }