-/* $OpenBSD: conf.c,v 1.12 2017/11/25 19:02:07 patrick Exp $ */
+/* $OpenBSD: conf.c,v 1.13 2018/01/30 20:19:06 naddy Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include "efidev.h"
#include "efipxe.h"
-const char version[] = "3.36";
+const char version[] = "3.37";
#ifdef EFI_DEBUG
int debug = 0;
-/* $OpenBSD: efipxe.c,v 1.2 2018/01/21 21:37:01 patrick Exp $ */
+/* $OpenBSD: efipxe.c,v 1.3 2018/01/30 20:19:06 naddy Exp $ */
/*
* Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
*
}
tftpfile->inbufsize = size;
+ if (tftpfile->inbufsize == 0)
+ goto out;
+
status = EFI_CALL(BS->AllocatePages, AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(tftpfile->inbufsize), &addr);
if (status != EFI_SUCCESS) {
free(tftpfile, sizeof(*tftpfile));
return ENXIO;
}
-
+out:
f->f_fsdata = tftpfile;
return 0;
}
{
struct tftp_handle *tftpfile = f->f_fsdata;
- EFI_CALL(BS->FreePages, (paddr_t)tftpfile->inbuf,
- EFI_SIZE_TO_PAGES(tftpfile->inbufsize));
+ if (tftpfile->inbuf != NULL)
+ EFI_CALL(BS->FreePages, (paddr_t)tftpfile->inbuf,
+ EFI_SIZE_TO_PAGES(tftpfile->inbufsize));
free(tftpfile, sizeof(*tftpfile));
return 0;
}
else
toread = size;
- if (toread == 0) {
- if (resid != NULL)
- *resid = 0;
- return (0);
+ if (toread != 0) {
+ memcpy(addr, tftpfile->inbuf + tftpfile->inbufoff, toread);
+ tftpfile->inbufoff += toread;
}
- memcpy(addr, tftpfile->inbuf + tftpfile->inbufoff, toread);
- tftpfile->inbufoff += toread;
-
if (resid != NULL)
*resid = size - toread;
return 0;
switch(where) {
case SEEK_CUR:
- if (tftpfile->inbufoff + offset < 0) {
+ if (tftpfile->inbufoff + offset < 0 ||
+ tftpfile->inbufoff + offset > tftpfile->inbufsize) {
errno = EOFFSET;
break;
}
-/* $OpenBSD: conf.c,v 1.10 2018/01/21 21:35:34 patrick Exp $ */
+/* $OpenBSD: conf.c,v 1.11 2018/01/30 20:19:06 naddy Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
#include "efidev.h"
#include "efipxe.h"
-const char version[] = "0.9";
+const char version[] = "0.10";
int debug = 0;
struct fs_ops file_system[] = {
-/* $OpenBSD: efipxe.c,v 1.1 2018/01/21 21:35:34 patrick Exp $ */
+/* $OpenBSD: efipxe.c,v 1.2 2018/01/30 20:19:06 naddy Exp $ */
/*
* Copyright (c) 2017 Patrick Wildt <patrick@blueri.se>
*
}
tftpfile->inbufsize = size;
+ if (tftpfile->inbufsize == 0)
+ goto out;
+
status = EFI_CALL(BS->AllocatePages, AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(tftpfile->inbufsize), &addr);
if (status != EFI_SUCCESS) {
free(tftpfile, sizeof(*tftpfile));
return ENXIO;
}
-
+out:
f->f_fsdata = tftpfile;
return 0;
}
{
struct tftp_handle *tftpfile = f->f_fsdata;
- EFI_CALL(BS->FreePages, (paddr_t)tftpfile->inbuf,
- EFI_SIZE_TO_PAGES(tftpfile->inbufsize));
+ if (tftpfile->inbuf != NULL)
+ EFI_CALL(BS->FreePages, (paddr_t)tftpfile->inbuf,
+ EFI_SIZE_TO_PAGES(tftpfile->inbufsize));
free(tftpfile, sizeof(*tftpfile));
return 0;
}
else
toread = size;
- if (toread == 0) {
- if (resid != NULL)
- *resid = 0;
- return (0);
+ if (toread != 0) {
+ memcpy(addr, tftpfile->inbuf + tftpfile->inbufoff, toread);
+ tftpfile->inbufoff += toread;
}
- memcpy(addr, tftpfile->inbuf + tftpfile->inbufoff, toread);
- tftpfile->inbufoff += toread;
-
if (resid != NULL)
*resid = size - toread;
return 0;
switch(where) {
case SEEK_CUR:
- if (tftpfile->inbufoff + offset < 0) {
+ if (tftpfile->inbufoff + offset < 0 ||
+ tftpfile->inbufoff + offset > tftpfile->inbufsize) {
errno = EOFFSET;
break;
}