File: string_t

package info (click to toggle)
mig 1.8%2Bgit20231217-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,560 kB
  • sloc: ansic: 5,194; sh: 4,751; yacc: 590; lex: 286; makefile: 121; awk: 45
file content (27 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
commit 6c4b92f9e9a8ac9f9df3ca1cc5ddb50b4faaaf3f
Author: Flavio Cruz <flaviocruz@gmail.com>
Date:   Sun Feb 9 22:38:26 2025 -0500

    Server routines: ensure that strings in the request are null terminated before calling the server routine
    
    Message-ID: <neoj66xitwcilmtlf3fek6tjal35tuetleyydiduuqvhkjisah@n2a2xwvoqrie>

diff --git a/server.c b/server.c
index 8da231c..9d25573 100644
--- a/server.c
+++ b/server.c
@@ -766,6 +766,14 @@ WriteExtractArg(FILE *file, const argument_t *arg)
 	    WriteInitializeCount(file, arg);
     }
 
+    /* Ensure strings are null-terminated */
+    const ipc_type_t *it = arg->argType;
+    if (akCheck(arg->argKind, akbSend) && it->itString && !it->itVarArray) {
+	const size_t total_bytes = (it->itSize * it->itNumber)/8;
+	fprintf(file, "\t/* Ensure %s is null-terminated */\n", arg->argVarName);
+	fprintf(file, "\t%s[%d] = \'\\0\';\n", InArgMsgField(arg), total_bytes - 1);
+    }
+
     if (akCheckAll(arg->argKind, akbReturnSnd|akbPointer))
 	WriteInitializePtr(file, arg);
     if (akCheckAll(arg->argKind, akbSendRcv|akbPointer)) {