[commit/pushed] Fix bug when saving the receipt file using a .DEC filename as template

Thadeu Lima de Souza Cascardo cascardo en cascardo.info
Mar Abr 29 00:33:23 UTC 2014


Sergio Durigan Junior <sergiodj en sergiodj.net> wrote:
>This commit fixes a bug that happens when the user provides a .DEC
>filename to be transmitted, and rnetclient uses this filename to
>compose
>the receipt (.REC) filename to be saved.  I forgot to use "basename" to
>extract only the .DEC filename (and strip all the other paths) before
>using
>it to build the .REC full path.  As an addition, this commit also fixes
>a small memory leak.  Tested by sending a declaration again.
>---
> rnetclient.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/rnetclient.c b/rnetclient.c
>index 3b9ce1e..e37a723 100644
>--- a/rnetclient.c
>+++ b/rnetclient.c
>@@ -18,6 +18,7 @@
>  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  */
> 
>+#define _GNU_SOURCE
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>
>@@ -378,9 +379,9 @@ static void save_rec_file(char *cpf, char *buffer,
>int len, const struct rnetcli
> 	   the receipt with the name "$CPF.REC".  */
> 	tmp = strstr(args->input_file, ".DEC");
> 	if (tmp != NULL && tmp[sizeof(".DEC") - 1] == '\0') {
>-		const char *p;
>+		char *p;
> 		/* We found the ".REC" extension.  */
>-		p = strdup(args->input_file);
>+		p = strdup(basename(args->input_file));
> 		/* Replacing the ".DEC" by ".REC".  Fortunately, we
> 		   just have to change one letter.  */
> 		tmp = strstr(p, ".DEC");
>@@ -388,6 +389,7 @@ static void save_rec_file(char *cpf, char *buffer,
>int len, const struct rnetcli
> 		fname_len = strlen(p) + strlen(path) + 2;
> 		fname = alloca(fname_len);
> 		snprintf(fname, fname_len, "%s/%s", path, p);
>+		free(p);
> 	} else {
> 		/* The declaration filename does not follow the
> 		   convention, so we will not use it as a template.

This should have been two commits. Next time.  :)

Cascardo.


Más información sobre la lista de distribución Softwares-impostos